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 authored and Simon Kelley committed 2021-12-04 12:03:31 +00:00
1 parent ed96efd865
commit 44a4643b62
1 file changed
+1 -1
+1 -1
View File
@@ -663,7 +663,7 @@ static char *canonicalise_opt(char *s)
return 0;
if (strlen(s) == 0)
return opt_string_alloc("");
return opt_malloc(1); /* Heap-allocated empty string */
unhide_metas(s);
if (!(ret = canonicalise(s, &nomem)) && nomem)