Skip to content

Commit f1fa94a

Browse files
committed
Fix logic to prevent pg_dump from dumping system schemas; bug introduced
in recent -t/-n/-T/-N patch. Small style cleanups.
1 parent 959aee5 commit f1fa94a

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.444 2006/08/01 21:05:00 momjian Exp $
15+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.445 2006/08/02 21:43:43 momjian Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -625,6 +625,7 @@ main(int argc, char **argv)
625625
/* Check schema selection flags */
626626
resetPQExpBuffer(query);
627627
switch_include_exclude = true;
628+
628629
for (this_obj_name = schemaList; this_obj_name; this_obj_name = this_obj_name->next)
629630
{
630631
if (switch_include_exclude)
@@ -686,6 +687,7 @@ main(int argc, char **argv)
686687
/* Check table selection flags */
687688
resetPQExpBuffer(query);
688689
switch_include_exclude = true;
690+
689691
for (this_obj_name = tableList; this_obj_name; this_obj_name = this_obj_name->next)
690692
{
691693
if (switch_include_exclude)
@@ -937,21 +939,23 @@ selectDumpableNamespace(NamespaceInfo *nsinfo)
937939
* namespaces. If specific namespaces are being dumped, dump just
938940
* those namespaces. Otherwise, dump all non-system namespaces.
939941
*/
942+
nsinfo->dobj.dump = false;
943+
940944
if (matchingTables != NULL)
941-
nsinfo->dobj.dump = false;
945+
/* false */;
942946
else if (matchingSchemas != NULL)
943947
{
944-
char *searchname = NULL;
945-
searchname = malloc(20);
946-
sprintf(searchname, " %d ", nsinfo->dobj.catId.oid);
947-
if (strstr(matchingSchemas, searchname) != NULL)
948+
char *search_oid = malloc(20);
949+
950+
sprintf(search_oid, " %d ", nsinfo->dobj.catId.oid);
951+
if (strstr(matchingSchemas, search_oid) != NULL)
948952
nsinfo->dobj.dump = true;
949-
free(searchname);
953+
954+
free(search_oid);
950955
}
951-
else if (strncmp(nsinfo->dobj.name, "pg_", 3) == 0 ||
952-
strcmp(nsinfo->dobj.name, "information_schema") == 0)
953-
nsinfo->dobj.dump = false;
954-
else
956+
/* The server prevents users from creating pg_ schemas */
957+
else if (strncmp(nsinfo->dobj.name, "pg_", 3) != 0 &&
958+
strcmp(nsinfo->dobj.name, "information_schema") != 0)
955959
nsinfo->dobj.dump = true;
956960
}
957961

@@ -968,16 +972,21 @@ selectDumpableTable(TableInfo *tbinfo)
968972
* dump.
969973
*/
970974
tbinfo->dobj.dump = false;
971-
if (tbinfo->dobj.namespace->dobj.dump || matchingTables == NULL)
972-
tbinfo->dobj.dump = true;
975+
976+
if (matchingTables == NULL)
977+
{
978+
if (tbinfo->dobj.namespace->dobj.dump)
979+
tbinfo->dobj.dump = true;
980+
}
973981
else
974982
{
975-
char *searchname = NULL;
976-
searchname = malloc(20);
977-
sprintf(searchname, " %d ", tbinfo->dobj.catId.oid);
978-
if (strstr(matchingTables, searchname) != NULL)
983+
char *search_oid = malloc(20);
984+
985+
sprintf(search_oid, " %d ", tbinfo->dobj.catId.oid);
986+
if (strstr(matchingTables, search_oid) != NULL)
979987
tbinfo->dobj.dump = true;
980-
free(searchname);
988+
989+
free(search_oid);
981990
}
982991
}
983992

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