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

Commit47c0f00

Browse files
committed
Be more wary about NULL values for GUC string variables.
get_explain_guc_options() crashed if a string GUC marked GUC_EXPLAINhas a NULL boot_val. Nosing around found a couple of other placesthat seemed insufficiently cautious about NULL string values, althoughthose are likely unreachable in practice. Add some commentarydefining the expectations for NULL values of string variables,in hopes of forestalling future additions of more such bugs.Xing Guo, Aleksander Alekseev, Tom LaneDiscussion:https://postgr.es/m/CACpMh+AyDx5YUpPaAgzVwC1d8zfOL4JoD-uyFDnNSa1z0EsDQQ@mail.gmail.com
1 parent52a105e commit47c0f00

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9522,7 +9522,14 @@ get_explain_guc_options(int *num)
95229522
{
95239523
structconfig_string*lconf= (structconfig_string*)conf;
95249524

9525-
modified= (strcmp(lconf->boot_val,*(lconf->variable))!=0);
9525+
if (lconf->boot_val==NULL&&
9526+
*lconf->variable==NULL)
9527+
modified= false;
9528+
elseif (lconf->boot_val==NULL||
9529+
*lconf->variable==NULL)
9530+
modified= true;
9531+
else
9532+
modified= (strcmp(lconf->boot_val,*(lconf->variable))!=0);
95269533
}
95279534
break;
95289535

@@ -10269,7 +10276,8 @@ write_one_nondefault_variable(FILE *fp, struct config_generic *gconf)
1026910276
{
1027010277
structconfig_string*conf= (structconfig_string*)gconf;
1027110278

10272-
fprintf(fp,"%s",*conf->variable);
10279+
if (*conf->variable)
10280+
fprintf(fp,"%s",*conf->variable);
1027310281
}
1027410282
break;
1027510283

‎src/include/utils/guc_tables.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,16 @@ struct config_real
218218
void*reset_extra;
219219
};
220220

221+
/*
222+
* A note about string GUCs: the boot_val is allowed to be NULL, which leads
223+
* to the reset_val and the actual variable value (*variable) also being NULL.
224+
* However, there is no way to set a NULL value subsequently using
225+
* set_config_option or any other GUC API. Also, GUC APIs such as SHOW will
226+
* display a NULL value as an empty string. Callers that choose to use a NULL
227+
* boot_val should overwrite the setting later in startup, or else be careful
228+
* that NULL doesn't have semantics that are visibly different from an empty
229+
* string.
230+
*/
221231
structconfig_string
222232
{
223233
structconfig_genericgen;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp