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

Commit404c45b

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 parentd932391 commit404c45b

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
@@ -9856,18 +9856,59 @@ flatten_reloptions(Oid relid)
98569856
Anum_pg_class_reloptions,&isnull);
98579857
if (!isnull)
98589858
{
9859-
Datumsep,
9860-
txt;
9859+
StringInfoDatabuf;
9860+
Datum*options;
9861+
intnoptions;
9862+
inti;
98619863

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

98739914
ReleaseSysCache(tuple);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp