Skip to content

Commit ef1f158

Browse files
Fix bug in TOC file error message printing
If the blob TOC file cannot be parsed, the error message was failing to print the filename as the variable holding it was shadowed by the destination buffer for parsing. When the filename fails to parse, the error will print an empty string: ./pg_restore -d foo -F d dump pg_restore: error: invalid line in large object TOC file "": .. ..instead of the intended error message: ./pg_restore -d foo -F d dump pg_restore: error: invalid line in large object TOC file "dump/blobs.toc": .. Fix by renaming both variables as the shared name was too generic to store either and still convey what the variable held. Backpatch all the way down to 9.6. Reviewed-by: Tom Lane Discussion: https://postgr.es/m/A2B151F5-B32B-4F2C-BA4A-6870856D9BDE@yesql.se Backpatch-through: 9.6
1 parent 6b96aaf commit ef1f158

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/bin/pg_dump/pg_backup_directory.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -447,42 +447,42 @@ _LoadBlobs(ArchiveHandle *AH)
447447
{
448448
Oid oid;
449449
lclContext *ctx = (lclContext *) AH->formatData;
450-
char fname[MAXPGPATH];
450+
char tocfname[MAXPGPATH];
451451
char line[MAXPGPATH];
452452

453453
StartRestoreBlobs(AH);
454454

455-
setFilePath(AH, fname, "blobs.toc");
455+
setFilePath(AH, tocfname, "blobs.toc");
456456

457-
ctx->blobsTocFH = cfopen_read(fname, PG_BINARY_R);
457+
ctx->blobsTocFH = cfopen_read(tocfname, PG_BINARY_R);
458458

459459
if (ctx->blobsTocFH == NULL)
460460
exit_horribly(modulename, "could not open large object TOC file \"%s\" for input: %s\n",
461-
fname, strerror(errno));
461+
tocfname, strerror(errno));
462462

463463
/* Read the blobs TOC file line-by-line, and process each blob */
464464
while ((cfgets(ctx->blobsTocFH, line, MAXPGPATH)) != NULL)
465465
{
466-
char fname[MAXPGPATH + 1];
466+
char blobfname[MAXPGPATH + 1];
467467
char path[MAXPGPATH];
468468

469-
/* Can't overflow because line and fname are the same length. */
470-
if (sscanf(line, "%u %" CppAsString2(MAXPGPATH) "s\n", &oid, fname) != 2)
469+
/* Can't overflow because line and blobfname are the same length. */
470+
if (sscanf(line, "%u %" CppAsString2(MAXPGPATH) "s\n", &oid, blobfname) != 2)
471471
exit_horribly(modulename, "invalid line in large object TOC file \"%s\": \"%s\"\n",
472-
fname, line);
472+
tocfname, line);
473473

474474
StartRestoreBlob(AH, oid, AH->public.ropt->dropSchema);
475-
snprintf(path, MAXPGPATH, "%s/%s", ctx->directory, fname);
475+
snprintf(path, MAXPGPATH, "%s/%s", ctx->directory, blobfname);
476476
_PrintFileData(AH, path);
477477
EndRestoreBlob(AH, oid);
478478
}
479479
if (!cfeof(ctx->blobsTocFH))
480480
exit_horribly(modulename, "error reading large object TOC file \"%s\"\n",
481-
fname);
481+
tocfname);
482482

483483
if (cfclose(ctx->blobsTocFH) != 0)
484484
exit_horribly(modulename, "could not close large object TOC file \"%s\": %s\n",
485-
fname, strerror(errno));
485+
tocfname, strerror(errno));
486486

487487
ctx->blobsTocFH = NULL;
488488

0 commit comments

Comments
 (0)