Correctly return a heap-allocated empty string instead of NULL

Commit 32e15c3f45 added the following
change:

  --- a/src/option.c
  +++ b/src/option.c
  @@ -654,7 +654,7 @@ static char *canonicalise_opt(char *s)
       return 0;

     if (strlen(s) == 0)
  -    return "";
  +    return opt_string_alloc("");

     unhide_metas(s);
     if (!(ret = canonicalise(s, &nomem)) && nomem)

Unfortunately, opt_string_alloc(const char *cp) returns NULL when
strlen(cp) == 0, which in turn causes --rebind-domain-ok='' to crash
with SIGSEGV.
This commit is contained in:
guns
2021-11-17 14:15:35 -06:00
committed by Simon Kelley
parent ed96efd865
commit 44a4643b62

View File

@@ -663,7 +663,7 @@ static char *canonicalise_opt(char *s)
return 0; return 0;
if (strlen(s) == 0) if (strlen(s) == 0)
return opt_string_alloc(""); return opt_malloc(1); /* Heap-allocated empty string */
unhide_metas(s); unhide_metas(s);
if (!(ret = canonicalise(s, &nomem)) && nomem) if (!(ret = canonicalise(s, &nomem)) && nomem)