Skip to content

Commit 6e1cca5

Browse files
committed
Be more wary about NULL values for GUC string variables.
get_explain_guc_options() crashed if a string GUC marked GUC_EXPLAIN has a NULL boot_val. Nosing around found a couple of other places that seemed insufficiently cautious about NULL string values, although those are likely unreachable in practice. Add some commentary defining the expectations for NULL values of string variables, in hopes of forestalling future additions of more such bugs. Xing Guo, Aleksander Alekseev, Tom Lane Discussion: https://postgr.es/m/CACpMh+AyDx5YUpPaAgzVwC1d8zfOL4JoD-uyFDnNSa1z0EsDQQ@mail.gmail.com
1 parent f8b96c2 commit 6e1cca5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/backend/utils/misc/guc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9122,7 +9122,8 @@ write_one_nondefault_variable(FILE *fp, struct config_generic *gconf)
91229122
{
91239123
struct config_string *conf = (struct config_string *) gconf;
91249124

9125-
fprintf(fp, "%s", *conf->variable);
9125+
if (*conf->variable)
9126+
fprintf(fp, "%s", *conf->variable);
91269127
}
91279128
break;
91289129

src/include/utils/guc_tables.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@ struct config_real
221221
void *reset_extra;
222222
};
223223

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy