<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19242">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_geolocation: Fix segfault when there's an empty element<br><br>Fixed a segfault caused by var_list_from_loc_info() encountering<br>an empty location info element.<br><br>Fixed an issue in ast_strsep() where a value with only whitespace<br>wasn't being preserved.<br><br>Fixed an issue in ast_variable_list_from_quoted_string() where<br>an empty value was considered a failure.<br><br>ASTERISK-30215<br>Reported by: Dan Cropp<br><br>Change-Id: Ieca64e061a6d9298f0196c694b60d986ef82613a<br>---<br>M include/asterisk/strings.h<br>M main/config.c<br>M main/utils.c<br>M res/res_geolocation/geoloc_eprofile.c<br>M tests/test_config.c<br>5 files changed, 44 insertions(+), 13 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/42/19242/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h</span><br><span>index d0a4cbb..f8ad414 100644</span><br><span>--- a/include/asterisk/strings.h</span><br><span>+++ b/include/asterisk/strings.h</span><br><span>@@ -265,6 +265,7 @@</span><br><span>   \param sep A single character delimiter.</span><br><span>   \param flags Controls post-processing of the result.</span><br><span>   AST_STRSEP_TRIM trims all leading and trailing whitespace from the result.</span><br><span style="color: hsl(120, 100%, 40%);">+  If the result containes only whitespace, it'll be passed through unchanged.</span><br><span>   AST_STRSEP_STRIP does a trim then strips the outermost quotes.  You may want</span><br><span>   to trim again after the strip.  Just OR both the TRIM and STRIP flags.</span><br><span>   AST_STRSEP_UNESCAPE unescapes '\' sequences.</span><br><span>diff --git a/main/config.c b/main/config.c</span><br><span>index 0e27d76..1074407 100644</span><br><span>--- a/main/config.c</span><br><span>+++ b/main/config.c</span><br><span>@@ -646,15 +646,16 @@</span><br><span> struct ast_variable *ast_variable_list_append_hint(struct ast_variable **head, struct ast_variable *search_hint, struct ast_variable *newvar)</span><br><span> {</span><br><span>         struct ast_variable *curr;</span><br><span style="color: hsl(120, 100%, 40%);">+    struct ast_variable *sh = search_hint;</span><br><span>       ast_assert(head != NULL);</span><br><span> </span><br><span>        if (!*head) {</span><br><span>                *head = newvar;</span><br><span>      } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                if (search_hint == NULL) {</span><br><span style="color: hsl(0, 100%, 40%);">-                      search_hint = *head;</span><br><span style="color: hsl(120, 100%, 40%);">+          if (sh == NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+                     sh = *head;</span><br><span>          }</span><br><span style="color: hsl(0, 100%, 40%);">-               for (curr = search_hint; curr->next; curr = curr->next);</span><br><span style="color: hsl(120, 100%, 40%);">+                for (curr = sh; curr->next; curr = curr->next);</span><br><span>                curr->next = newvar;</span><br><span>      }</span><br><span> </span><br><span>@@ -752,12 +753,8 @@</span><br><span>                 }</span><br><span> </span><br><span>                item_value = ast_strsep_quoted(&item, nv_sep, quote, AST_STRSEP_ALL);</span><br><span style="color: hsl(0, 100%, 40%);">-               if (!item_value) {</span><br><span style="color: hsl(0, 100%, 40%);">-                      ast_variables_destroy(new_list);</span><br><span style="color: hsl(0, 100%, 40%);">-                        return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-            }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-           new_var = ast_variable_new(item_name, item_value, "");</span><br><span style="color: hsl(120, 100%, 40%);">+              new_var = ast_variable_new(item_name, item_value ?: "", "");</span><br><span>             if (!new_var) {</span><br><span>                      ast_variables_destroy(new_list);</span><br><span>                     return NULL;</span><br><span>diff --git a/main/utils.c b/main/utils.c</span><br><span>index 3ab6dc1..6111b86 100644</span><br><span>--- a/main/utils.c</span><br><span>+++ b/main/utils.c</span><br><span>@@ -1849,7 +1849,10 @@</span><br><span>   }</span><br><span> </span><br><span>        if (flags & AST_STRSEP_TRIM) {</span><br><span style="color: hsl(0, 100%, 40%);">-              st = ast_strip(st);</span><br><span style="color: hsl(120, 100%, 40%);">+           char *trimmed = ast_strip(st);</span><br><span style="color: hsl(120, 100%, 40%);">+                if (!ast_strlen_zero(trimmed)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                      st = trimmed;</span><br><span style="color: hsl(120, 100%, 40%);">+         }</span><br><span>    }</span><br><span> </span><br><span>        if (flags & AST_STRSEP_UNESCAPE) {</span><br><span>@@ -1910,7 +1913,10 @@</span><br><span>      }</span><br><span> </span><br><span>        if (flags & AST_STRSEP_TRIM) {</span><br><span style="color: hsl(0, 100%, 40%);">-              st = ast_strip(st);</span><br><span style="color: hsl(120, 100%, 40%);">+           char *trimmed = ast_strip(st);</span><br><span style="color: hsl(120, 100%, 40%);">+                if (!ast_strlen_zero(trimmed)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                      st = trimmed;</span><br><span style="color: hsl(120, 100%, 40%);">+         }</span><br><span>    }</span><br><span> </span><br><span>        if (flags & AST_STRSEP_UNESCAPE) {</span><br><span>diff --git a/res/res_geolocation/geoloc_eprofile.c b/res/res_geolocation/geoloc_eprofile.c</span><br><span>index 864dd23..09a06c6 100644</span><br><span>--- a/res/res_geolocation/geoloc_eprofile.c</span><br><span>+++ b/res/res_geolocation/geoloc_eprofile.c</span><br><span>@@ -498,6 +498,7 @@</span><br><span>        enum ast_geoloc_format format, const char *ref_str)</span><br><span> {</span><br><span>     struct ast_variable *list = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+     struct ast_variable *locinfo_list = NULL;</span><br><span>    struct ast_xml_node *container;</span><br><span>      struct ast_variable *var = NULL;</span><br><span>     const char *attr;</span><br><span>@@ -531,7 +532,12 @@</span><br><span>             ast_variable_list_append(&list, var);</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   ast_variable_list_append(&list, var_list_from_node(container, ref_str));</span><br><span style="color: hsl(120, 100%, 40%);">+  locinfo_list = var_list_from_node(container, ref_str);</span><br><span style="color: hsl(120, 100%, 40%);">+        if (locinfo_list == NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+           ast_log(LOG_WARNING, "%s: There were no elements in the location info\n", ref_str);</span><br><span style="color: hsl(120, 100%, 40%);">+         SCOPE_EXIT_RTN_VALUE(list, "%s: There were no elements in the location info\n", ref_str);</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+     ast_variable_list_append(&list, locinfo_list);</span><br><span> </span><br><span>       if (TRACE_ATLEAST(5)) {</span><br><span>              struct ast_str *buf = NULL;</span><br><span>diff --git a/tests/test_config.c b/tests/test_config.c</span><br><span>index 166879a..1d44e5d 100644</span><br><span>--- a/tests/test_config.c</span><br><span>+++ b/tests/test_config.c</span><br><span>@@ -1961,13 +1961,13 @@</span><br><span>               break;</span><br><span>       }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   parse_string = "abc = 'def', ghi = 'j,kl', mno='pq=r', stu = 'vwx=\"yz\", ABC = \"DEF\"'";</span><br><span style="color: hsl(120, 100%, 40%);">+      parse_string = "000= '', 111=, 222 = , 333 = ' ', abc = 'def', ghi = 'j,kl', mno='pq=r', stu = 'vwx=\"yz\", ABC = \"DEF\"'";</span><br><span>   list = ast_variable_list_from_quoted_string(parse_string, ",", "=", "'");</span><br><span>  ast_test_validate(test, list != NULL);</span><br><span>       str = ast_variable_list_join(list, "|", "^", "@", NULL);</span><br><span> </span><br><span>   ast_test_validate(test,</span><br><span style="color: hsl(0, 100%, 40%);">-         strcmp(ast_str_buffer(str), "abc^@def@|ghi^@j,kl@|mno^@pq=r@|stu^@vwx=\"yz\", ABC = \"DEF\"@") == 0);</span><br><span style="color: hsl(120, 100%, 40%);">+           strcmp(ast_str_buffer(str), "000^@@|111^@@|222^@@|333^@ @|abc^@def@|ghi^@j,kl@|mno^@pq=r@|stu^@vwx=\"yz\", ABC = \"DEF\"@") == 0);</span><br><span> </span><br><span>         return AST_TEST_PASS;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19242">change 19242</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/19242"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ieca64e061a6d9298f0196c694b60d986ef82613a </div>
<div style="display:none"> Gerrit-Change-Number: 19242 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>