1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

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
This commit is contained in:
Tom Lane
2023-11-02 11:47:33 -04:00
parent 4b14e18714
commit 7704a1a72e
2 changed files with 23 additions and 3 deletions

View File

@ -1473,7 +1473,9 @@ check_GUC_init(struct config_generic *gconf)
{
struct config_string *conf = (struct config_string *) gconf;
if (*conf->variable != NULL && strcmp(*conf->variable, conf->boot_val) != 0)
if (*conf->variable != NULL &&
(conf->boot_val == NULL ||
strcmp(*conf->variable, conf->boot_val) != 0))
{
elog(LOG, "GUC (PGC_STRING) %s, boot_val=%s, C-var=%s",
conf->gen.name, conf->boot_val ? conf->boot_val : "<null>", *conf->variable);
@ -5255,7 +5257,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;
@ -5482,7 +5491,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;