Commit 3636efa1 authored by Thomas Munro's avatar Thomas Munro

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: default avatarMichael Paquier <michael@paquier.xyz>
parent 8b39345a
......@@ -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,
if (strlen(inddependcollnames) == 0 && strlen(inddependcollversions) == 0)
{
ninddependcollnames = ninddependcollversions = 0;
inddependcollnamesarray = inddependcollversionsarray = NULL;
}
else
{
if (!parsePGArray(inddependcollnames,
&inddependcollnamesarray,
&ninddependcollnames);
parsePGArray(inddependcollversions,
&ninddependcollnames))
fatal("could not parse index collation name array");
if (!parsePGArray(inddependcollversions,
&inddependcollversionsarray,
&ninddependcollversions);
Assert(ninddependcollnames == ninddependcollversions);
&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");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment