postgres.git / summary / log / commit / refs

commit    f1431f3bffa00962ae8debb98a750ed2fb09fa3b
Author:   Michael Paquier <michael@paquier.xyz>
Date:     Sat May 28 03:12:40 2022 +0000
First released in: 15.0, 10.22, 11.17, 12.12, 13.8, 14.4

    Handle NULL for short descriptions of custom GUC variables
    
    If a short description is specified as NULL in one of the various
    DefineCustomXXXVariable() functions available to external modules to
    define a custom parameter, SHOW ALL would crash.  This change teaches
    SHOW ALL to properly handle NULL short descriptions, as well as any code
    paths that manipulate it, to gain in flexibility.  Note that
    help_config.c was already able to do that, when describing a set of GUCs
    for postgres --describe-config.
    
    Author: Steve Chavez
    Reviewed by: Nathan Bossart, Andres Freund, Michael Paquier, Tom Lane
    Discussion: https://postgr.es/m/CAGRrpzY6hO-Kmykna_XvsTv8P2DshGiU6G3j8yGao4mk0CqjHA%40mail.gmail.com
    Backpatch-through: 10


src/backend/utils/misc/guc.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 8e9b71375ce..55d41ae7d63 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -9780,7 +9780,16 @@ ShowAllGUCConfig(DestReceiver *dest) isnull[1] = true; } - values[2] = PointerGetDatum(cstring_to_text(conf->short_desc)); + if (conf->short_desc) + { + values[2] = PointerGetDatum(cstring_to_text(conf->short_desc)); + isnull[2] = false; + } + else + { + values[2] = PointerGetDatum(NULL); + isnull[2] = true; + } /* send it to dest */ do_tup_output(tstate, values, isnull); @@ -9792,7 +9801,8 @@ ShowAllGUCConfig(DestReceiver *dest) pfree(setting); pfree(DatumGetPointer(values[1])); } - pfree(DatumGetPointer(values[2])); + if (conf->short_desc) + pfree(DatumGetPointer(values[2])); } end_tup_output(tstate); @@ -10002,7 +10012,7 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow) values[3] = _(config_group_names[conf->group]); /* short_desc */ - values[4] = _(conf->short_desc); + values[4] = conf->short_desc != NULL ? _(conf->short_desc) : NULL; /* extra_desc */ values[5] = conf->long_desc != NULL ? _(conf->long_desc) : NULL; [parent: 3e9abd2eb1b1]