Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 13b58f8

Browse files
committed
Improve failure detection with array parsing in pg_dump
Similarly to 3636efa, the checks done in pg_dump when parsing array values from catalogs have been too lax. Under memory pressure, it could be possible, though very unlikely, to finish with dumps that miss some data like: - Statistics for indexes - Run-time configuration of functions - Configuration of extensions - Publication list for a subscription No backpatch is done as this is not going to be a problem in practice. For example, if an OOM causes an array parsing to fail, a follow-up code path of pg_dump would most likely complain with an allocation failure due to the memory pressure. Author: Michael Paquier Reviewed-by: Daniel Gustafsson Discussion: https://postgr.es/m/20201111061319.GE2276@paquier.xyz
1 parent 2783898 commit 13b58f8

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

src/bin/pg_dump/pg_dump.c

+27-24
Original file line numberDiff line numberDiff line change
@@ -4357,13 +4357,7 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
43574357

43584358
/* Build list of quoted publications and append them to query. */
43594359
if (!parsePGArray(subinfo->subpublications, &pubnames, &npubnames))
4360-
{
4361-
pg_log_warning("could not parse subpublications array");
4362-
if (pubnames)
4363-
free(pubnames);
4364-
pubnames = NULL;
4365-
npubnames = 0;
4366-
}
4360+
fatal("could not parse subpublications array");
43674361

43684362
publications = createPQExpBuffer();
43694363
for (i = 0; i < npubnames; i++)
@@ -12128,13 +12122,12 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
1212812122
if (proconfig && *proconfig)
1212912123
{
1213012124
if (!parsePGArray(proconfig, &configitems, &nconfigitems))
12131-
{
12132-
pg_log_warning("could not parse proconfig array");
12133-
if (configitems)
12134-
free(configitems);
12135-
configitems = NULL;
12136-
nconfigitems = 0;
12137-
}
12125+
fatal("could not parse proconfig array");
12126+
}
12127+
else
12128+
{
12129+
configitems = NULL;
12130+
nconfigitems = 0;
1213812131
}
1213912132

1214012133
if (funcargs)
@@ -16453,8 +16446,8 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
1645316446
char *indstatvals = indxinfo->indstatvals;
1645416447
char **indstatcolsarray = NULL;
1645516448
char **indstatvalsarray = NULL;
16456-
int nstatcols;
16457-
int nstatvals;
16449+
int nstatcols = 0;
16450+
int nstatvals = 0;
1645816451

1645916452
if (dopt->binary_upgrade)
1646016453
binary_upgrade_set_pg_class_oids(fout, q,
@@ -16483,12 +16476,17 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
1648316476
* If the index has any statistics on some of its columns, generate
1648416477
* the associated ALTER INDEX queries.
1648516478
*/
16486-
if (parsePGArray(indstatcols, &indstatcolsarray, &nstatcols) &&
16487-
parsePGArray(indstatvals, &indstatvalsarray, &nstatvals) &&
16488-
nstatcols == nstatvals)
16479+
if (strlen(indstatcols) != 0 || strlen(indstatvals) != 0)
1648916480
{
1649016481
int j;
1649116482

16483+
if (!parsePGArray(indstatcols, &indstatcolsarray, &nstatcols))
16484+
fatal("could not parse index statistic columns");
16485+
if (!parsePGArray(indstatvals, &indstatvalsarray, &nstatvals))
16486+
fatal("could not parse index statistic values");
16487+
if (nstatcols != nstatvals)
16488+
fatal("mismatched number of columns and values for index stats");
16489+
1649216490
for (j = 0; j < nstatcols; j++)
1649316491
{
1649416492
appendPQExpBuffer(q, "ALTER INDEX %s ", qqindxname);
@@ -17938,15 +17936,20 @@ processExtensionTables(Archive *fout, ExtensionInfo extinfo[],
1793817936
char *extcondition = curext->extcondition;
1793917937
char **extconfigarray = NULL;
1794017938
char **extconditionarray = NULL;
17941-
int nconfigitems;
17942-
int nconditionitems;
17939+
int nconfigitems = 0;
17940+
int nconditionitems = 0;
1794317941

17944-
if (parsePGArray(extconfig, &extconfigarray, &nconfigitems) &&
17945-
parsePGArray(extcondition, &extconditionarray, &nconditionitems) &&
17946-
nconfigitems == nconditionitems)
17942+
if (strlen(extconfig) != 0 || strlen(extcondition) != 0)
1794717943
{
1794817944
int j;
1794917945

17946+
if (!parsePGArray(extconfig, &extconfigarray, &nconfigitems))
17947+
fatal("could not parse extension configuration array");
17948+
if (!parsePGArray(extcondition, &extconditionarray, &nconditionitems))
17949+
fatal("could not parse extension condition array");
17950+
if (nconfigitems != nconditionitems)
17951+
fatal("mismatched number of configurations and conditions for extension");
17952+
1795017953
for (j = 0; j < nconfigitems; j++)
1795117954
{
1795217955
TableInfo *configtbl;

0 commit comments

Comments
 (0)