Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc7e27be

Browse files
committed
Teach flatten_reloptions() to quote option values safely.
flatten_reloptions() supposed that it didn't really need to do anythingbeyond inserting commas between reloption array elements. However, inprinciple the value of a reloption could be nearly anything, since thegrammar allows a quoted string there. Any restrictions on it would comefrom validity checking appropriate to the particular option, if any.A reloption value that isn't a simple identifier or number could thus leadto dump/reload failures due to syntax errors in CREATE statements issuedby pg_dump. We've gotten away with not worrying about this so far withthe core-supported reloptions, but extensions might allow reloption valuesthat cause trouble, as in bug #13840 from Kouhei Sutou.To fix, split the reloption array elements explicitly, and then convertany value that doesn't look like a safe identifier to a string literal.(The details of the quoting rule could be debated, but this way is safeand requires little code.) While we're at it, also quote reloption namesif they're not safe identifiers; that may not be a likely problem in thefield, but we might as well try to be bulletproof here.It's been like this for a long time, so back-patch to all supportedbranches.Kouhei Sutou, adjusted some by me
1 parent3c93a60 commitc7e27be

File tree

1 file changed

+52
-11
lines changed

1 file changed

+52
-11
lines changed

‎src/backend/utils/adt/ruleutils.c

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9858,18 +9858,59 @@ flatten_reloptions(Oid relid)
98589858
Anum_pg_class_reloptions,&isnull);
98599859
if (!isnull)
98609860
{
9861-
Datumsep,
9862-
txt;
9861+
StringInfoDatabuf;
9862+
Datum*options;
9863+
intnoptions;
9864+
inti;
98639865

9864-
/*
9865-
* We want to use array_to_text(reloptions, ', ') --- but
9866-
* DirectFunctionCall2(array_to_text) does not work, because
9867-
* array_to_text() relies on flinfo to be valid. So use
9868-
* OidFunctionCall2.
9869-
*/
9870-
sep=CStringGetTextDatum(", ");
9871-
txt=OidFunctionCall2(F_ARRAY_TO_TEXT,reloptions,sep);
9872-
result=TextDatumGetCString(txt);
9866+
initStringInfo(&buf);
9867+
9868+
deconstruct_array(DatumGetArrayTypeP(reloptions),
9869+
TEXTOID,-1, false,'i',
9870+
&options,NULL,&noptions);
9871+
9872+
for (i=0;i<noptions;i++)
9873+
{
9874+
char*option=TextDatumGetCString(options[i]);
9875+
char*name;
9876+
char*separator;
9877+
char*value;
9878+
9879+
/*
9880+
* Each array element should have the form name=value. If the "="
9881+
* is missing for some reason, treat it like an empty value.
9882+
*/
9883+
name=option;
9884+
separator=strchr(option,'=');
9885+
if (separator)
9886+
{
9887+
*separator='\0';
9888+
value=separator+1;
9889+
}
9890+
else
9891+
value="";
9892+
9893+
if (i>0)
9894+
appendStringInfoString(&buf,", ");
9895+
appendStringInfo(&buf,"%s=",quote_identifier(name));
9896+
9897+
/*
9898+
* In general we need to quote the value; but to avoid unnecessary
9899+
* clutter, do not quote if it is an identifier that would not
9900+
* need quoting. (We could also allow numbers, but that is a bit
9901+
* trickier than it looks --- for example, are leading zeroes
9902+
* significant? We don't want to assume very much here about what
9903+
* custom reloptions might mean.)
9904+
*/
9905+
if (quote_identifier(value)==value)
9906+
appendStringInfoString(&buf,value);
9907+
else
9908+
simple_quote_literal(&buf,value);
9909+
9910+
pfree(option);
9911+
}
9912+
9913+
result=buf.data;
98739914
}
98749915

98759916
ReleaseSysCache(tuple);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp