Skip to content

Commit 19455c9

Browse files
committed
pg_dump: Fix ArchiveEntry handling of some empty values
Commit f831d4a changed what pg_dump emits for some empty fields: they were output as empty strings before, NULL pointer afterwards. That makes old pg_restore unable to work (crash) with such files, which is unacceptable. Return to the original representation by explicitly setting those struct members to "" where needed; remove some no longer needed checks for NULL input. We can declutter the code a little by returning to NULLs when we next update the archive version, so add a note to remind us later. Discussion: https://postgr.es/m/20190225074539.az6j3u464cvsoxh6@depesz.com Reported-by: hubert depesz lubaczewski Author: Dmitry Dolgov
1 parent 3f61999 commit 19455c9

File tree

3 files changed

+58
-16
lines changed

3 files changed

+58
-16
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,10 +1090,10 @@ ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId,
10901090
newToc->tag = pg_strdup(opts->tag);
10911091
newToc->namespace = opts->namespace ? pg_strdup(opts->namespace) : NULL;
10921092
newToc->tablespace = opts->tablespace ? pg_strdup(opts->tablespace) : NULL;
1093-
newToc->owner = opts->owner ? pg_strdup(opts->owner) : NULL;
1093+
newToc->owner = pg_strdup(opts->owner);
10941094
newToc->desc = pg_strdup(opts->description);
1095-
newToc->defn = opts->createStmt ? pg_strdup(opts->createStmt) : NULL;
1096-
newToc->dropStmt = opts->dropStmt ? pg_strdup(opts->dropStmt) : NULL;
1095+
newToc->defn = pg_strdup(opts->createStmt);
1096+
newToc->dropStmt = pg_strdup(opts->dropStmt);
10971097
newToc->copyStmt = opts->copyStmt ? pg_strdup(opts->copyStmt) : NULL;
10981098

10991099
if (opts->nDeps > 0)
@@ -3600,7 +3600,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData)
36003600
}
36013601
else
36023602
{
3603-
if (te->defn && strlen(te->defn) > 0)
3603+
if (strlen(te->defn) > 0)
36043604
ahprintf(AH, "%s\n\n", te->defn);
36053605
}
36063606

@@ -3611,8 +3611,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData)
36113611
* with DROP commands must appear in one list or the other.
36123612
*/
36133613
if (!ropt->noOwner && !ropt->use_setsessauth &&
3614-
te->owner && strlen(te->owner) > 0 &&
3615-
te->dropStmt && strlen(te->dropStmt) > 0)
3614+
strlen(te->owner) > 0 && strlen(te->dropStmt) > 0)
36163615
{
36173616
if (strcmp(te->desc, "AGGREGATE") == 0 ||
36183617
strcmp(te->desc, "BLOB") == 0 ||

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ typedef z_stream *z_streamp;
9595
#define K_VERS_1_13 MAKE_ARCHIVE_VERSION(1, 13, 0) /* change search_path
9696
* behavior */
9797

98-
/* Current archive version number (the format we can output) */
98+
/*
99+
* Current archive version number (the format we can output)
100+
*
101+
* Note: If you update the current archive version, consider
102+
* https://postgr.es/m/20190227123217.GA27552@alvherre.pgsql
103+
*/
99104
#define K_VERS_MAJOR 1
100105
#define K_VERS_MINOR 13
101106
#define K_VERS_REV 0

src/bin/pg_dump/pg_dump.c

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,8 @@ dumpTableData(Archive *fout, TableDataInfo *tdinfo)
21652165
.owner = tbinfo->rolname,
21662166
.description = "TABLE DATA",
21672167
.section = SECTION_DATA,
2168+
.createStmt = "",
2169+
.dropStmt = "",
21682170
.copyStmt = copyStmt,
21692171
.deps = &(tbinfo->dobj.dumpId),
21702172
.nDeps = 1,
@@ -2219,6 +2221,7 @@ refreshMatViewData(Archive *fout, TableDataInfo *tdinfo)
22192221
.description = "MATERIALIZED VIEW DATA",
22202222
.section = SECTION_POST_DATA,
22212223
.createStmt = q->data,
2224+
.dropStmt = "",
22222225
.deps = tdinfo->dobj.dependencies,
22232226
.nDeps = tdinfo->dobj.nDeps));
22242227

@@ -2784,6 +2787,7 @@ dumpDatabase(Archive *fout)
27842787
.description = "COMMENT",
27852788
.section = SECTION_NONE,
27862789
.createStmt = dbQry->data,
2790+
.dropStmt = "",
27872791
.deps = &dbDumpId,
27882792
.nDeps = 1));
27892793
}
@@ -2813,6 +2817,7 @@ dumpDatabase(Archive *fout)
28132817
.description = "SECURITY LABEL",
28142818
.section = SECTION_NONE,
28152819
.createStmt = seclabelQry->data,
2820+
.dropStmt = "",
28162821
.deps = &dbDumpId,
28172822
.nDeps = 1));
28182823
destroyPQExpBuffer(seclabelQry);
@@ -2929,8 +2934,10 @@ dumpDatabase(Archive *fout)
29292934
ArchiveEntry(fout, nilCatalogId, createDumpId(),
29302935
ARCHIVE_OPTS(.tag = "pg_largeobject",
29312936
.description = "pg_largeobject",
2937+
.owner = "",
29322938
.section = SECTION_PRE_DATA,
2933-
.createStmt = loOutQry->data));
2939+
.createStmt = loOutQry->data,
2940+
.dropStmt = ""));
29342941

29352942
PQclear(lo_res);
29362943

@@ -3038,8 +3045,10 @@ dumpEncoding(Archive *AH)
30383045
ArchiveEntry(AH, nilCatalogId, createDumpId(),
30393046
ARCHIVE_OPTS(.tag = "ENCODING",
30403047
.description = "ENCODING",
3048+
.owner = "",
30413049
.section = SECTION_PRE_DATA,
3042-
.createStmt = qry->data));
3050+
.createStmt = qry->data,
3051+
.dropStmt = ""));
30433052

30443053
destroyPQExpBuffer(qry);
30453054
}
@@ -3064,8 +3073,10 @@ dumpStdStrings(Archive *AH)
30643073
ArchiveEntry(AH, nilCatalogId, createDumpId(),
30653074
ARCHIVE_OPTS(.tag = "STDSTRINGS",
30663075
.description = "STDSTRINGS",
3076+
.owner = "",
30673077
.section = SECTION_PRE_DATA,
3068-
.createStmt = qry->data));
3078+
.createStmt = qry->data,
3079+
.dropStmt = ""));
30693080

30703081
destroyPQExpBuffer(qry);
30713082
}
@@ -3119,8 +3130,10 @@ dumpSearchPath(Archive *AH)
31193130
ArchiveEntry(AH, nilCatalogId, createDumpId(),
31203131
ARCHIVE_OPTS(.tag = "SEARCHPATH",
31213132
.description = "SEARCHPATH",
3133+
.owner = "",
31223134
.section = SECTION_PRE_DATA,
3123-
.createStmt = qry->data));
3135+
.createStmt = qry->data,
3136+
.dropStmt = ""));
31243137

31253138
/* Also save it in AH->searchpath, in case we're doing plain text dump */
31263139
AH->searchpath = pg_strdup(qry->data);
@@ -3601,6 +3614,7 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo)
36013614
.description = "ROW SECURITY",
36023615
.section = SECTION_POST_DATA,
36033616
.createStmt = query->data,
3617+
.dropStmt = "",
36043618
.deps = &(tbinfo->dobj.dumpId),
36053619
.nDeps = 1));
36063620

@@ -3968,8 +3982,10 @@ dumpPublicationTable(Archive *fout, PublicationRelInfo *pubrinfo)
39683982
ARCHIVE_OPTS(.tag = tag,
39693983
.namespace = tbinfo->dobj.namespace->dobj.name,
39703984
.description = "PUBLICATION TABLE",
3985+
.owner = "",
39713986
.section = SECTION_POST_DATA,
3972-
.createStmt = query->data));
3987+
.createStmt = query->data,
3988+
.dropStmt = ""));
39733989

39743990
free(tag);
39753991
destroyPQExpBuffer(query);
@@ -9393,6 +9409,7 @@ dumpComment(Archive *fout, const char *type, const char *name,
93939409
.description = "COMMENT",
93949410
.section = SECTION_NONE,
93959411
.createStmt = query->data,
9412+
.dropStmt = "",
93969413
.deps = &dumpId,
93979414
.nDeps = 1));
93989415

@@ -9462,6 +9479,7 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo,
94629479
.description = "COMMENT",
94639480
.section = SECTION_NONE,
94649481
.createStmt = query->data,
9482+
.dropStmt = "",
94659483
.deps = &(tbinfo->dobj.dumpId),
94669484
.nDeps = 1));
94679485
}
@@ -9487,6 +9505,7 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo,
94879505
.description = "COMMENT",
94889506
.section = SECTION_NONE,
94899507
.createStmt = query->data,
9508+
.dropStmt = "",
94909509
.deps = &(tbinfo->dobj.dumpId),
94919510
.nDeps = 1));
94929511
}
@@ -9767,8 +9786,11 @@ dumpDumpableObject(Archive *fout, DumpableObject *dobj)
97679786
te = ArchiveEntry(fout, dobj->catId, dobj->dumpId,
97689787
ARCHIVE_OPTS(.tag = dobj->name,
97699788
.description = "BLOBS",
9789+
.owner = "",
97709790
.section = SECTION_DATA,
9771-
.dumpFn = dumpBlobs));
9791+
.dumpFn = dumpBlobs,
9792+
.createStmt = "",
9793+
.dropStmt = ""));
97729794

97739795
/*
97749796
* Set the TocEntry's dataLength in case we are doing a
@@ -9973,6 +9995,7 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo)
99739995
ArchiveEntry(fout, extinfo->dobj.catId, extinfo->dobj.dumpId,
99749996
ARCHIVE_OPTS(.tag = extinfo->dobj.name,
99759997
.description = "EXTENSION",
9998+
.owner = "",
99769999
.section = SECTION_PRE_DATA,
997710000
.createStmt = q->data,
997810001
.dropStmt = delq->data));
@@ -11116,6 +11139,7 @@ dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo)
1111611139
.description = "COMMENT",
1111711140
.section = SECTION_NONE,
1111811141
.createStmt = query->data,
11142+
.dropStmt = "",
1111911143
.deps = &(tyinfo->dobj.dumpId),
1112011144
.nDeps = 1));
1112111145
}
@@ -11171,7 +11195,8 @@ dumpShellType(Archive *fout, ShellTypeInfo *stinfo)
1117111195
.owner = stinfo->baseType->rolname,
1117211196
.description = "SHELL TYPE",
1117311197
.section = SECTION_PRE_DATA,
11174-
.createStmt = q->data));
11198+
.createStmt = q->data,
11199+
.dropStmt = ""));
1117511200

1117611201
destroyPQExpBuffer(q);
1117711202
}
@@ -12116,6 +12141,7 @@ dumpCast(Archive *fout, CastInfo *cast)
1211612141
ArchiveEntry(fout, cast->dobj.catId, cast->dobj.dumpId,
1211712142
ARCHIVE_OPTS(.tag = labelq->data,
1211812143
.description = "CAST",
12144+
.owner = "",
1211912145
.section = SECTION_PRE_DATA,
1212012146
.createStmt = defqry->data,
1212112147
.dropStmt = delqry->data));
@@ -12243,6 +12269,7 @@ dumpTransform(Archive *fout, TransformInfo *transform)
1224312269
ArchiveEntry(fout, transform->dobj.catId, transform->dobj.dumpId,
1224412270
ARCHIVE_OPTS(.tag = labelq->data,
1224512271
.description = "TRANSFORM",
12272+
.owner = "",
1224612273
.section = SECTION_PRE_DATA,
1224712274
.createStmt = defqry->data,
1224812275
.dropStmt = delqry->data,
@@ -12626,6 +12653,7 @@ dumpAccessMethod(Archive *fout, AccessMethodInfo *aminfo)
1262612653
ArchiveEntry(fout, aminfo->dobj.catId, aminfo->dobj.dumpId,
1262712654
ARCHIVE_OPTS(.tag = aminfo->dobj.name,
1262812655
.description = "ACCESS METHOD",
12656+
.owner = "",
1262912657
.section = SECTION_PRE_DATA,
1263012658
.createStmt = q->data,
1263112659
.dropStmt = delq->data));
@@ -14077,6 +14105,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo)
1407714105
ARCHIVE_OPTS(.tag = prsinfo->dobj.name,
1407814106
.namespace = prsinfo->dobj.namespace->dobj.name,
1407914107
.description = "TEXT SEARCH PARSER",
14108+
.owner = "",
1408014109
.section = SECTION_PRE_DATA,
1408114110
.createStmt = q->data,
1408214111
.dropStmt = delq->data));
@@ -14215,6 +14244,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo)
1421514244
ARCHIVE_OPTS(.tag = tmplinfo->dobj.name,
1421614245
.namespace = tmplinfo->dobj.namespace->dobj.name,
1421714246
.description = "TEXT SEARCH TEMPLATE",
14247+
.owner = "",
1421814248
.section = SECTION_PRE_DATA,
1421914249
.createStmt = q->data,
1422014250
.dropStmt = delq->data));
@@ -14684,7 +14714,8 @@ dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo)
1468414714
.owner = daclinfo->defaclrole,
1468514715
.description = "DEFAULT ACL",
1468614716
.section = SECTION_POST_DATA,
14687-
.createStmt = q->data));
14717+
.createStmt = q->data,
14718+
.dropStmt = ""));
1468814719

1468914720
destroyPQExpBuffer(tag);
1469014721
destroyPQExpBuffer(q);
@@ -14782,6 +14813,7 @@ dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId,
1478214813
.description = "ACL",
1478314814
.section = SECTION_NONE,
1478414815
.createStmt = sql->data,
14816+
.dropStmt = "",
1478514817
.deps = &objDumpId,
1478614818
.nDeps = 1));
1478714819
destroyPQExpBuffer(tag);
@@ -14871,6 +14903,7 @@ dumpSecLabel(Archive *fout, const char *type, const char *name,
1487114903
.description = "SECURITY LABEL",
1487214904
.section = SECTION_NONE,
1487314905
.createStmt = query->data,
14906+
.dropStmt = "",
1487414907
.deps = &dumpId,
1487514908
.nDeps = 1));
1487614909
destroyPQExpBuffer(tag);
@@ -14954,6 +14987,7 @@ dumpTableSecLabel(Archive *fout, TableInfo *tbinfo, const char *reltypename)
1495414987
.description = "SECURITY LABEL",
1495514988
.section = SECTION_NONE,
1495614989
.createStmt = query->data,
14990+
.dropStmt = "",
1495714991
.deps = &(tbinfo->dobj.dumpId),
1495814992
.nDeps = 1));
1495914993
}
@@ -16313,8 +16347,10 @@ dumpIndexAttach(Archive *fout, IndexAttachInfo *attachinfo)
1631316347
ARCHIVE_OPTS(.tag = attachinfo->dobj.name,
1631416348
.namespace = attachinfo->dobj.namespace->dobj.name,
1631516349
.description = "INDEX ATTACH",
16350+
.owner = "",
1631616351
.section = SECTION_POST_DATA,
16317-
.createStmt = q->data));
16352+
.createStmt = q->data,
16353+
.dropStmt = ""));
1631816354

1631916355
destroyPQExpBuffer(q);
1632016356
}
@@ -16944,6 +16980,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
1694416980
.description = "SEQUENCE OWNED BY",
1694516981
.section = SECTION_PRE_DATA,
1694616982
.createStmt = query->data,
16983+
.dropStmt = "",
1694716984
.deps = &(tbinfo->dobj.dumpId),
1694816985
.nDeps = 1));
1694916986
}
@@ -17012,6 +17049,7 @@ dumpSequenceData(Archive *fout, TableDataInfo *tdinfo)
1701217049
.description = "SEQUENCE SET",
1701317050
.section = SECTION_DATA,
1701417051
.createStmt = query->data,
17052+
.dropStmt = "",
1701517053
.deps = &(tbinfo->dobj.dumpId),
1701617054
.nDeps = 1));
1701717055

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy