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

Commit82063ed

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 parente22819a commit82063ed

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,9 @@ check_GUC_init(struct config_generic *gconf)
14451445
{
14461446
structconfig_string*conf= (structconfig_string*)gconf;
14471447

1448-
if (*conf->variable!=NULL&&strcmp(*conf->variable,conf->boot_val)!=0)
1448+
if (*conf->variable!=NULL&&
1449+
(conf->boot_val==NULL||
1450+
strcmp(*conf->variable,conf->boot_val)!=0))
14491451
{
14501452
elog(LOG,"GUC (PGC_STRING) %s, boot_val=%s, C-var=%s",
14511453
conf->gen.name,conf->boot_val ?conf->boot_val :"<null>",*conf->variable);
@@ -5215,7 +5217,14 @@ get_explain_guc_options(int *num)
52155217
{
52165218
structconfig_string*lconf= (structconfig_string*)conf;
52175219

5218-
modified= (strcmp(lconf->boot_val,*(lconf->variable))!=0);
5220+
if (lconf->boot_val==NULL&&
5221+
*lconf->variable==NULL)
5222+
modified= false;
5223+
elseif (lconf->boot_val==NULL||
5224+
*lconf->variable==NULL)
5225+
modified= true;
5226+
else
5227+
modified= (strcmp(lconf->boot_val,*(lconf->variable))!=0);
52195228
}
52205229
break;
52215230

@@ -5442,7 +5451,8 @@ write_one_nondefault_variable(FILE *fp, struct config_generic *gconf)
54425451
{
54435452
structconfig_string*conf= (structconfig_string*)gconf;
54445453

5445-
fprintf(fp,"%s",*conf->variable);
5454+
if (*conf->variable)
5455+
fprintf(fp,"%s",*conf->variable);
54465456
}
54475457
break;
54485458

‎src/include/utils/guc_tables.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ struct config_real
240240
void*reset_extra;
241241
};
242242

243+
/*
244+
* A note about string GUCs: the boot_val is allowed to be NULL, which leads
245+
* to the reset_val and the actual variable value (*variable) also being NULL.
246+
* However, there is no way to set a NULL value subsequently using
247+
* set_config_option or any other GUC API. Also, GUC APIs such as SHOW will
248+
* display a NULL value as an empty string. Callers that choose to use a NULL
249+
* boot_val should overwrite the setting later in startup, or else be careful
250+
* that NULL doesn't have semantics that are visibly different from an empty
251+
* string.
252+
*/
243253
structconfig_string
244254
{
245255
structconfig_genericgen;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp