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

Commit 998d060

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 1d7641d commit 998d060

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/bin/pg_dump/pg_backup_directory.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -433,42 +433,42 @@ _LoadBlobs(ArchiveHandle *AH)
433433
{
434434
Oid oid;
435435
lclContext *ctx = (lclContext *) AH->formatData;
436-
char fname[MAXPGPATH];
436+
char tocfname[MAXPGPATH];
437437
char line[MAXPGPATH];
438438

439439
StartRestoreBlobs(AH);
440440

441-
setFilePath(AH, fname, "blobs.toc");
441+
setFilePath(AH, tocfname, "blobs.toc");
442442

443-
ctx->blobsTocFH = cfopen_read(fname, PG_BINARY_R);
443+
ctx->blobsTocFH = cfopen_read(tocfname, PG_BINARY_R);
444444

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

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

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

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

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

473473
ctx->blobsTocFH = NULL;
474474

0 commit comments

Comments
 (0)