Skip to content

Commit 4fda03b

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 abdf81a commit 4fda03b

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
@@ -442,42 +442,42 @@ _LoadBlobs(ArchiveHandle *AH)
442442
{
443443
Oid oid;
444444
lclContext *ctx = (lclContext *) AH->formatData;
445-
char fname[MAXPGPATH];
445+
char tocfname[MAXPGPATH];
446446
char line[MAXPGPATH];
447447

448448
StartRestoreBlobs(AH);
449449

450-
setFilePath(AH, fname, "blobs.toc");
450+
setFilePath(AH, tocfname, "blobs.toc");
451451

452-
ctx->blobsTocFH = cfopen_read(fname, PG_BINARY_R);
452+
ctx->blobsTocFH = cfopen_read(tocfname, PG_BINARY_R);
453453

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

458458
/* Read the blobs TOC file line-by-line, and process each blob */
459459
while ((cfgets(ctx->blobsTocFH, line, MAXPGPATH)) != NULL)
460460
{
461-
char fname[MAXPGPATH + 1];
461+
char blobfname[MAXPGPATH + 1];
462462
char path[MAXPGPATH];
463463

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

469469
StartRestoreBlob(AH, oid, AH->public.ropt->dropSchema);
470-
snprintf(path, MAXPGPATH, "%s/%s", ctx->directory, fname);
470+
snprintf(path, MAXPGPATH, "%s/%s", ctx->directory, blobfname);
471471
_PrintFileData(AH, path);
472472
EndRestoreBlob(AH, oid);
473473
}
474474
if (!cfeof(ctx->blobsTocFH))
475475
exit_horribly(modulename, "error reading large object TOC file \"%s\"\n",
476-
fname);
476+
tocfname);
477477

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

482482
ctx->blobsTocFH = NULL;
483483

0 commit comments

Comments
 (0)