diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-02-28 17:16:08 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-02-28 17:19:44 -0300 |
commit | 19455c9f5606072a191962271c35ad659fbab526 (patch) | |
tree | 630ad889675790e1c5db63e2da3f7d7fcab794ae /src/bin/pg_dump/pg_backup_archiver.c | |
parent | 3f61999cc9da68890174dd8cf97f2cb96b223e81 (diff) | |
download | postgresql-19455c9f5606072a191962271c35ad659fbab526.tar.gz postgresql-19455c9f5606072a191962271c35ad659fbab526.zip |
pg_dump: Fix ArchiveEntry handling of some empty values
Commit f831d4acc 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
Diffstat (limited to 'src/bin/pg_dump/pg_backup_archiver.c')
-rw-r--r-- | src/bin/pg_dump/pg_backup_archiver.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 8b55f5952c3..0f1afeacf79 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -1090,10 +1090,10 @@ ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, newToc->tag = pg_strdup(opts->tag); newToc->namespace = opts->namespace ? pg_strdup(opts->namespace) : NULL; newToc->tablespace = opts->tablespace ? pg_strdup(opts->tablespace) : NULL; - newToc->owner = opts->owner ? pg_strdup(opts->owner) : NULL; + newToc->owner = pg_strdup(opts->owner); newToc->desc = pg_strdup(opts->description); - newToc->defn = opts->createStmt ? pg_strdup(opts->createStmt) : NULL; - newToc->dropStmt = opts->dropStmt ? pg_strdup(opts->dropStmt) : NULL; + newToc->defn = pg_strdup(opts->createStmt); + newToc->dropStmt = pg_strdup(opts->dropStmt); newToc->copyStmt = opts->copyStmt ? pg_strdup(opts->copyStmt) : NULL; if (opts->nDeps > 0) @@ -3600,7 +3600,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData) } else { - if (te->defn && strlen(te->defn) > 0) + if (strlen(te->defn) > 0) ahprintf(AH, "%s\n\n", te->defn); } @@ -3611,8 +3611,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData) * with DROP commands must appear in one list or the other. */ if (!ropt->noOwner && !ropt->use_setsessauth && - te->owner && strlen(te->owner) > 0 && - te->dropStmt && strlen(te->dropStmt) > 0) + strlen(te->owner) > 0 && strlen(te->dropStmt) > 0) { if (strcmp(te->desc, "AGGREGATE") == 0 || strcmp(te->desc, "BLOB") == 0 || |