Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fb2aece

Browse files
committed
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
1 parent 7fc5f1a commit fb2aece

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

contrib/pg_archivecleanup/pg_archivecleanup.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ CleanupPriorWALFiles(void)
108108
{
109109
while (errno = 0, (xlde = readdir(xldir)) != NULL)
110110
{
111-
strncpy(walfile, xlde->d_name, MAXPGPATH);
111+
/*
112+
* Truncation is essentially harmless, because we skip names of
113+
* length other than XLOG_DATA_FNAME_LEN. (In principle, one
114+
* could use a 1000-character additional_ext and get trouble.)
115+
*/
116+
strlcpy(walfile, xlde->d_name, MAXPGPATH);
112117
TrimExtension(walfile, additional_ext);
113118

114119
/*

src/backend/access/transam/xlogarchive.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,8 @@ KeepFileRestoredFromArchive(char *path, char *xlogfname)
459459
xlogfpath, oldpath)));
460460
}
461461
#else
462-
strncpy(oldpath, xlogfpath, MAXPGPATH);
462+
/* same-size buffers, so this never truncates */
463+
strlcpy(oldpath, xlogfpath, MAXPGPATH);
463464
#endif
464465
if (unlink(oldpath) != 0)
465466
ereport(FATAL,

0 commit comments

Comments
 (0)