Commit fb2aece8 authored by Noah Misch's avatar Noah Misch

Replace a few strncmp() calls with strlcpy().

strncmp() is a specialized API unsuited for routine copying into
fixed-size buffers.  On a system where the length of a single filename
can exceed MAXPGPATH, the pg_archivecleanup change prevents a simple
crash in the subsequent strlen().  Few filesystems support names that
long, and calling pg_archivecleanup with untrusted input is still not a
credible use case.  Therefore, no back-patch.

David Rowley
parent 7fc5f1a3
...@@ -108,7 +108,12 @@ CleanupPriorWALFiles(void) ...@@ -108,7 +108,12 @@ CleanupPriorWALFiles(void)
{ {
while (errno = 0, (xlde = readdir(xldir)) != NULL) while (errno = 0, (xlde = readdir(xldir)) != NULL)
{ {
strncpy(walfile, xlde->d_name, MAXPGPATH); /*
* Truncation is essentially harmless, because we skip names of
* length other than XLOG_DATA_FNAME_LEN. (In principle, one
* could use a 1000-character additional_ext and get trouble.)
*/
strlcpy(walfile, xlde->d_name, MAXPGPATH);
TrimExtension(walfile, additional_ext); TrimExtension(walfile, additional_ext);
/* /*
......
...@@ -459,7 +459,8 @@ KeepFileRestoredFromArchive(char *path, char *xlogfname) ...@@ -459,7 +459,8 @@ KeepFileRestoredFromArchive(char *path, char *xlogfname)
xlogfpath, oldpath))); xlogfpath, oldpath)));
} }
#else #else
strncpy(oldpath, xlogfpath, MAXPGPATH); /* same-size buffers, so this never truncates */
strlcpy(oldpath, xlogfpath, MAXPGPATH);
#endif #endif
if (unlink(oldpath) != 0) if (unlink(oldpath) != 0)
ereport(FATAL, ereport(FATAL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment