Skip to content

Commit e788883

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 57bf8f7 commit e788883

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
@@ -435,42 +435,42 @@ _LoadBlobs(ArchiveHandle *AH)
435435
{
436436
Oid oid;
437437
lclContext *ctx = (lclContext *) AH->formatData;
438-
char fname[MAXPGPATH];
438+
char tocfname[MAXPGPATH];
439439
char line[MAXPGPATH];
440440

441441
StartRestoreBlobs(AH);
442442

443-
setFilePath(AH, fname, "blobs.toc");
443+
setFilePath(AH, tocfname, "blobs.toc");
444444

445-
ctx->blobsTocFH = cfopen_read(fname, PG_BINARY_R);
445+
ctx->blobsTocFH = cfopen_read(tocfname, PG_BINARY_R);
446446

447447
if (ctx->blobsTocFH == NULL)
448448
fatal("could not open large object TOC file \"%s\" for input: %m",
449-
fname);
449+
tocfname);
450450

451451
/* Read the blobs TOC file line-by-line, and process each blob */
452452
while ((cfgets(ctx->blobsTocFH, line, MAXPGPATH)) != NULL)
453453
{
454-
char fname[MAXPGPATH + 1];
454+
char blobfname[MAXPGPATH + 1];
455455
char path[MAXPGPATH];
456456

457-
/* Can't overflow because line and fname are the same length. */
458-
if (sscanf(line, "%u %" CppAsString2(MAXPGPATH) "s\n", &oid, fname) != 2)
457+
/* Can't overflow because line and blobfname are the same length */
458+
if (sscanf(line, "%u %" CppAsString2(MAXPGPATH) "s\n", &oid, blobfname) != 2)
459459
fatal("invalid line in large object TOC file \"%s\": \"%s\"",
460-
fname, line);
460+
tocfname, line);
461461

462462
StartRestoreBlob(AH, oid, AH->public.ropt->dropSchema);
463-
snprintf(path, MAXPGPATH, "%s/%s", ctx->directory, fname);
463+
snprintf(path, MAXPGPATH, "%s/%s", ctx->directory, blobfname);
464464
_PrintFileData(AH, path);
465465
EndRestoreBlob(AH, oid);
466466
}
467467
if (!cfeof(ctx->blobsTocFH))
468468
fatal("error reading large object TOC file \"%s\"",
469-
fname);
469+
tocfname);
470470

471471
if (cfclose(ctx->blobsTocFH) != 0)
472472
fatal("could not close large object TOC file \"%s\": %m",
473-
fname);
473+
tocfname);
474474

475475
ctx->blobsTocFH = NULL;
476476

0 commit comments

Comments
 (0)