mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-04 15:37:23 +02:00
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
This commit is contained in:
parent
57bf8f7b75
commit
e788883de7
@ -435,42 +435,42 @@ _LoadBlobs(ArchiveHandle *AH)
|
|||||||
{
|
{
|
||||||
Oid oid;
|
Oid oid;
|
||||||
lclContext *ctx = (lclContext *) AH->formatData;
|
lclContext *ctx = (lclContext *) AH->formatData;
|
||||||
char fname[MAXPGPATH];
|
char tocfname[MAXPGPATH];
|
||||||
char line[MAXPGPATH];
|
char line[MAXPGPATH];
|
||||||
|
|
||||||
StartRestoreBlobs(AH);
|
StartRestoreBlobs(AH);
|
||||||
|
|
||||||
setFilePath(AH, fname, "blobs.toc");
|
setFilePath(AH, tocfname, "blobs.toc");
|
||||||
|
|
||||||
ctx->blobsTocFH = cfopen_read(fname, PG_BINARY_R);
|
ctx->blobsTocFH = cfopen_read(tocfname, PG_BINARY_R);
|
||||||
|
|
||||||
if (ctx->blobsTocFH == NULL)
|
if (ctx->blobsTocFH == NULL)
|
||||||
fatal("could not open large object TOC file \"%s\" for input: %m",
|
fatal("could not open large object TOC file \"%s\" for input: %m",
|
||||||
fname);
|
tocfname);
|
||||||
|
|
||||||
/* Read the blobs TOC file line-by-line, and process each blob */
|
/* Read the blobs TOC file line-by-line, and process each blob */
|
||||||
while ((cfgets(ctx->blobsTocFH, line, MAXPGPATH)) != NULL)
|
while ((cfgets(ctx->blobsTocFH, line, MAXPGPATH)) != NULL)
|
||||||
{
|
{
|
||||||
char fname[MAXPGPATH + 1];
|
char blobfname[MAXPGPATH + 1];
|
||||||
char path[MAXPGPATH];
|
char path[MAXPGPATH];
|
||||||
|
|
||||||
/* Can't overflow because line and fname are the same length. */
|
/* Can't overflow because line and blobfname are the same length */
|
||||||
if (sscanf(line, "%u %" CppAsString2(MAXPGPATH) "s\n", &oid, fname) != 2)
|
if (sscanf(line, "%u %" CppAsString2(MAXPGPATH) "s\n", &oid, blobfname) != 2)
|
||||||
fatal("invalid line in large object TOC file \"%s\": \"%s\"",
|
fatal("invalid line in large object TOC file \"%s\": \"%s\"",
|
||||||
fname, line);
|
tocfname, line);
|
||||||
|
|
||||||
StartRestoreBlob(AH, oid, AH->public.ropt->dropSchema);
|
StartRestoreBlob(AH, oid, AH->public.ropt->dropSchema);
|
||||||
snprintf(path, MAXPGPATH, "%s/%s", ctx->directory, fname);
|
snprintf(path, MAXPGPATH, "%s/%s", ctx->directory, blobfname);
|
||||||
_PrintFileData(AH, path);
|
_PrintFileData(AH, path);
|
||||||
EndRestoreBlob(AH, oid);
|
EndRestoreBlob(AH, oid);
|
||||||
}
|
}
|
||||||
if (!cfeof(ctx->blobsTocFH))
|
if (!cfeof(ctx->blobsTocFH))
|
||||||
fatal("error reading large object TOC file \"%s\"",
|
fatal("error reading large object TOC file \"%s\"",
|
||||||
fname);
|
tocfname);
|
||||||
|
|
||||||
if (cfclose(ctx->blobsTocFH) != 0)
|
if (cfclose(ctx->blobsTocFH) != 0)
|
||||||
fatal("could not close large object TOC file \"%s\": %m",
|
fatal("could not close large object TOC file \"%s\": %m",
|
||||||
fname);
|
tocfname);
|
||||||
|
|
||||||
ctx->blobsTocFH = NULL;
|
ctx->blobsTocFH = NULL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user