Fix parsePGArray() error checking in pg_dump.

Coverity complained about a defect in commit 257836a7:

  Calling "parsePGArray" without checking return value (as is
  done elsewhere 11 out of 13 times).

Fix, and also check for empty strings explicitly (NULL as represented by
PQgetvalue()).  That worked correctly before only because parsePGArray()
happens to set *nitems = 0 when it fails on an empty string.  Also
convert a sanity check assertion to an error to be more paranoid, and
pgindent a nearby line.

Reported-by: Michael Paquier <michael@paquier.xyz>
This commit is contained in:
Thomas Munro 2020-11-09 16:01:51 +13:00
parent 8b39345a9d
commit 3636efa119
1 changed files with 20 additions and 8 deletions

View File

@ -18573,13 +18573,25 @@ appendIndexCollationVersion(PQExpBuffer buffer, IndxInfo *indxinfo, int enc,
}
/* Restore the versions that were recorded by the old cluster (if any). */
parsePGArray(inddependcollnames,
&inddependcollnamesarray,
&ninddependcollnames);
parsePGArray(inddependcollversions,
&inddependcollversionsarray,
&ninddependcollversions);
Assert(ninddependcollnames == ninddependcollversions);
if (strlen(inddependcollnames) == 0 && strlen(inddependcollversions) == 0)
{
ninddependcollnames = ninddependcollversions = 0;
inddependcollnamesarray = inddependcollversionsarray = NULL;
}
else
{
if (!parsePGArray(inddependcollnames,
&inddependcollnamesarray,
&ninddependcollnames))
fatal("could not parse index collation name array");
if (!parsePGArray(inddependcollversions,
&inddependcollversionsarray,
&ninddependcollversions))
fatal("could not parse index collation version array");
}
if (ninddependcollnames != ninddependcollversions)
fatal("mismatched number of collation names and versions for index");
if (ninddependcollnames > 0)
appendPQExpBufferStr(buffer,
@ -18594,7 +18606,7 @@ appendIndexCollationVersion(PQExpBuffer buffer, IndxInfo *indxinfo, int enc,
"UPDATE pg_catalog.pg_depend SET refobjversion = %s WHERE objid = '%u'::pg_catalog.oid AND refclassid = 'pg_catalog.pg_collation'::regclass AND refobjversion IS NOT NULL AND refobjid = ",
inddependcollversionsarray[i],
indxinfo->dobj.catId.oid);
appendStringLiteralAH(buffer,inddependcollnamesarray[i], fout);
appendStringLiteralAH(buffer, inddependcollnamesarray[i], fout);
appendPQExpBuffer(buffer, "::regcollation;\n");
}