aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/misc
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
commit65810fc6d0f6ccd3166713b9ec2f856be535383f (patch)
treeeb8b985ee287718226be38fb0d77e298f3f552ab /src/backend/utils/misc
parent616de5bb35734d2b88b2d3bc9a685925def893f2 (diff)
downloadpostgresql-65810fc6d0f6ccd3166713b9ec2f856be535383f.tar.gz
postgresql-65810fc6d0f6ccd3166713b9ec2f856be535383f.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
Diffstat (limited to 'src/backend/utils/misc')
-rw-r--r--src/backend/utils/misc/guc.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index bd03965a759..22d43287e36 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -8965,7 +8965,14 @@ get_explain_guc_options(int *num)
{
struct config_string *lconf = (struct config_string *) conf;
- modified = (strcmp(lconf->boot_val, *(lconf->variable)) != 0);
+ if (lconf->boot_val == NULL &&
+ *lconf->variable == NULL)
+ modified = false;
+ else if (lconf->boot_val == NULL ||
+ *lconf->variable == NULL)
+ modified = true;
+ else
+ modified = (strcmp(lconf->boot_val, *(lconf->variable)) != 0);
}
break;
@@ -9720,7 +9727,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;