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

Commitf3d1749

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 parent3644ac0 commitf3d1749

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
@@ -6857,22 +6857,37 @@ AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
68576857
errmsg("parameter \"%s\" cannot be changed",
68586858
name)));
68596859

6860+
/*
6861+
* If a value is specified, verify that it's sane.
6862+
*/
68606863
if (value)
68616864
{
68626865
unionconfig_var_valnewval;
68636866
void*newextra=NULL;
68646867

6868+
/* Check that it's acceptable for the indicated parameter */
68656869
if (!parse_and_validate_value(record,name,value,
68666870
PGC_S_FILE,ERROR,
68676871
&newval,&newextra))
68686872
ereport(ERROR,
6869-
(errmsg("invalid value for parameter \"%s\": \"%s\"",
6873+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6874+
errmsg("invalid value for parameter \"%s\": \"%s\"",
68706875
name,value)));
68716876

68726877
if (record->vartype==PGC_STRING&&newval.stringval!=NULL)
68736878
free(newval.stringval);
68746879
if (newextra)
68756880
free(newextra);
6881+
6882+
/*
6883+
* We must also reject values containing newlines, because the
6884+
* grammar for config files doesn't support embedded newlines in
6885+
* string literals.
6886+
*/
6887+
if (strchr(value,'\n'))
6888+
ereport(ERROR,
6889+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6890+
errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
68766891
}
68776892
}
68786893

@@ -6909,13 +6924,15 @@ AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
69096924
infile=AllocateFile(AutoConfFileName,"r");
69106925
if (infile==NULL)
69116926
ereport(ERROR,
6912-
(errmsg("could not open file \"%s\": %m",
6927+
(errcode_for_file_access(),
6928+
errmsg("could not open file \"%s\": %m",
69136929
AutoConfFileName)));
69146930

69156931
/* parse it */
69166932
if (!ParseConfigFp(infile,AutoConfFileName,0,LOG,&head,&tail))
69176933
ereport(ERROR,
6918-
(errmsg("could not parse contents of file \"%s\"",
6934+
(errcode(ERRCODE_CONFIG_FILE_ERROR),
6935+
errmsg("could not parse contents of file \"%s\"",
69196936
AutoConfFileName)));
69206937

69216938
FreeFile(infile);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp