]> granicus.if.org Git - postgresql/commitdiff
Fix unsafe extraction of the OID part of a relation filename.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 25 Mar 2018 19:15:32 +0000 (15:15 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 25 Mar 2018 19:15:40 +0000 (15:15 -0400)
Commit 8694cc96b did this randomly differently from other callers of
parse_filename_for_nontemp_relation().  Perhaps unsurprisingly,
the randomly different way is wrong; it fails to ensure the
extracted string is null-terminated.  Per buildfarm member skink.

Discussion: https://postgr.es/m/14453.1522001792@sss.pgh.pa.us

src/backend/replication/basebackup.c

index eb6eb7206da2177b8f9bb32c884dfad2f4c91557..e4c45c50256b39148af60df5431819f25881e49b 100644 (file)
@@ -1056,7 +1056,8 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
                                 * If any other type of fork, check if there is an init fork
                                 * with the same OID. If so, the file can be excluded.
                                 */
-                               strncpy(relOid, de->d_name, relOidChars);
+                               memcpy(relOid, de->d_name, relOidChars);
+                               relOid[relOidChars] = '\0';
                                snprintf(initForkFile, sizeof(initForkFile), "%s/%s_init",
                                                 path, relOid);