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

Commitf9b3b3f

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 parent76eccf0 commitf9b3b3f

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
@@ -9396,18 +9396,59 @@ flatten_reloptions(Oid relid)
93969396
Anum_pg_class_reloptions,&isnull);
93979397
if (!isnull)
93989398
{
9399-
Datumsep,
9400-
txt;
9399+
StringInfoDatabuf;
9400+
Datum*options;
9401+
intnoptions;
9402+
inti;
94019403

9402-
/*
9403-
* We want to use array_to_text(reloptions, ', ') --- but
9404-
* DirectFunctionCall2(array_to_text) does not work, because
9405-
* array_to_text() relies on flinfo to be valid. So use
9406-
* OidFunctionCall2.
9407-
*/
9408-
sep=CStringGetTextDatum(", ");
9409-
txt=OidFunctionCall2(F_ARRAY_TO_TEXT,reloptions,sep);
9410-
result=TextDatumGetCString(txt);
9404+
initStringInfo(&buf);
9405+
9406+
deconstruct_array(DatumGetArrayTypeP(reloptions),
9407+
TEXTOID,-1, false,'i',
9408+
&options,NULL,&noptions);
9409+
9410+
for (i=0;i<noptions;i++)
9411+
{
9412+
char*option=TextDatumGetCString(options[i]);
9413+
char*name;
9414+
char*separator;
9415+
char*value;
9416+
9417+
/*
9418+
* Each array element should have the form name=value. If the "="
9419+
* is missing for some reason, treat it like an empty value.
9420+
*/
9421+
name=option;
9422+
separator=strchr(option,'=');
9423+
if (separator)
9424+
{
9425+
*separator='\0';
9426+
value=separator+1;
9427+
}
9428+
else
9429+
value="";
9430+
9431+
if (i>0)
9432+
appendStringInfoString(&buf,", ");
9433+
appendStringInfo(&buf,"%s=",quote_identifier(name));
9434+
9435+
/*
9436+
* In general we need to quote the value; but to avoid unnecessary
9437+
* clutter, do not quote if it is an identifier that would not
9438+
* need quoting. (We could also allow numbers, but that is a bit
9439+
* trickier than it looks --- for example, are leading zeroes
9440+
* significant? We don't want to assume very much here about what
9441+
* custom reloptions might mean.)
9442+
*/
9443+
if (quote_identifier(value)==value)
9444+
appendStringInfoString(&buf,value);
9445+
else
9446+
simple_quote_literal(&buf,value);
9447+
9448+
pfree(option);
9449+
}
9450+
9451+
result=buf.data;
94119452
}
94129453

94139454
ReleaseSysCache(tuple);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp