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

Commit99f3b56

Browse files
committed
Disallow newlines in parameter values to be set in ALTER SYSTEM.
As noted by Julian Schauder in bug #14063, the configuration-file parserdoesn't support embedded newlines in string literals. While there mightsomeday be a good reason to remove that restriction, there doesn't seemto be one right now. However, ALTER SYSTEM SET could accept stringscontaining newlines, since many of the variable-specific value-checkingroutines would just see a newline as whitespace. This led to writing apostgresql.auto.conf file that was broken and had to be removed manually.Pending a reason to work harder, just throw an error if someone tries this.In passing, fix several places in the ALTER SYSTEM logic that failed toprovide an errcode() for an ereport(), and thus would falsely log thefailure as an internal XX000 error.Back-patch to 9.4 where ALTER SYSTEM was introduced.
1 parent890614d commit99f3b56

File tree

1 file changed

+20
-3
lines changed
  • src/backend/utils/misc

1 file changed

+20
-3
lines changed

‎src/backend/utils/misc/guc.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7000,22 +7000,37 @@ AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
70007000
errmsg("parameter \"%s\" cannot be changed",
70017001
name)));
70027002

7003+
/*
7004+
* If a value is specified, verify that it's sane.
7005+
*/
70037006
if (value)
70047007
{
70057008
unionconfig_var_valnewval;
70067009
void*newextra=NULL;
70077010

7011+
/* Check that it's acceptable for the indicated parameter */
70087012
if (!parse_and_validate_value(record,name,value,
70097013
PGC_S_FILE,ERROR,
70107014
&newval,&newextra))
70117015
ereport(ERROR,
7012-
(errmsg("invalid value for parameter \"%s\": \"%s\"",
7016+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7017+
errmsg("invalid value for parameter \"%s\": \"%s\"",
70137018
name,value)));
70147019

70157020
if (record->vartype==PGC_STRING&&newval.stringval!=NULL)
70167021
free(newval.stringval);
70177022
if (newextra)
70187023
free(newextra);
7024+
7025+
/*
7026+
* We must also reject values containing newlines, because the
7027+
* grammar for config files doesn't support embedded newlines in
7028+
* string literals.
7029+
*/
7030+
if (strchr(value,'\n'))
7031+
ereport(ERROR,
7032+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7033+
errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
70197034
}
70207035
}
70217036

@@ -7052,13 +7067,15 @@ AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
70527067
infile=AllocateFile(AutoConfFileName,"r");
70537068
if (infile==NULL)
70547069
ereport(ERROR,
7055-
(errmsg("could not open file \"%s\": %m",
7070+
(errcode_for_file_access(),
7071+
errmsg("could not open file \"%s\": %m",
70567072
AutoConfFileName)));
70577073

70587074
/* parse it */
70597075
if (!ParseConfigFp(infile,AutoConfFileName,0,LOG,&head,&tail))
70607076
ereport(ERROR,
7061-
(errmsg("could not parse contents of file \"%s\"",
7077+
(errcode(ERRCODE_CONFIG_FILE_ERROR),
7078+
errmsg("could not parse contents of file \"%s\"",
70627079
AutoConfFileName)));
70637080

70647081
FreeFile(infile);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp