aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-11-02 11:47:33 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2023-11-02 11:47:33 -0400
commit6e1cca5113487bb9ef4daa1bb2833c6333466410 (patch)
tree1fb280c892f1f99c8bebd83da048349941883d63
parentf8b96c211da0037269e31bd2be5e0f730ec5a2bc (diff)
downloadpostgresql-6e1cca5113487bb9ef4daa1bb2833c6333466410.tar.gz
postgresql-6e1cca5113487bb9ef4daa1bb2833c6333466410.zip
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
-rw-r--r--src/backend/utils/misc/guc.c3
-rw-r--r--src/include/utils/guc_tables.h10
2 files changed, 12 insertions, 1 deletions
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 1a9705af669..00eedbafca7 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -9122,7 +9122,8 @@ write_one_nondefault_variable(FILE *fp, struct config_generic *gconf)
{
struct config_string *conf = (struct config_string *) gconf;
- fprintf(fp, "%s", *conf->variable);
+ if (*conf->variable)
+ fprintf(fp, "%s", *conf->variable);
}
break;
diff --git a/src/include/utils/guc_tables.h b/src/include/utils/guc_tables.h
index 668d9efd357..9ea5c2a9ab5 100644
--- a/src/include/utils/guc_tables.h
+++ b/src/include/utils/guc_tables.h
@@ -221,6 +221,16 @@ struct config_real
void *reset_extra;
};
+/*
+ * A note about string GUCs: the boot_val is allowed to be NULL, which leads
+ * to the reset_val and the actual variable value (*variable) also being NULL.
+ * However, there is no way to set a NULL value subsequently using
+ * set_config_option or any other GUC API. Also, GUC APIs such as SHOW will
+ * display a NULL value as an empty string. Callers that choose to use a NULL
+ * boot_val should overwrite the setting later in startup, or else be careful
+ * that NULL doesn't have semantics that are visibly different from an empty
+ * string.
+ */
struct config_string
{
struct config_generic gen;