res_geolocation: Fix segfault when there's an empty element

Fixed a segfault caused by var_list_from_loc_info() encountering
an empty location info element.

Fixed an issue in ast_strsep() where a value with only whitespace
wasn't being preserved.

Fixed an issue in ast_variable_list_from_quoted_string() where
an empty value was considered a failure.

ASTERISK-30215
Reported by: Dan Cropp

Change-Id: Ieca64e061a6d9298f0196c694b60d986ef82613a
This commit is contained in:
George Joseph
2022-09-13 07:14:37 -06:00
parent fc63688e3b
commit bd2fb077ac
5 changed files with 23 additions and 13 deletions

View File

@@ -646,15 +646,16 @@ struct ast_variable *ast_variable_list_sort(struct ast_variable *start)
struct ast_variable *ast_variable_list_append_hint(struct ast_variable **head, struct ast_variable *search_hint, struct ast_variable *newvar)
{
struct ast_variable *curr;
struct ast_variable *sh = search_hint;
ast_assert(head != NULL);
if (!*head) {
*head = newvar;
} else {
if (search_hint == NULL) {
search_hint = *head;
if (sh == NULL) {
sh = *head;
}
for (curr = search_hint; curr->next; curr = curr->next);
for (curr = sh; curr->next; curr = curr->next);
curr->next = newvar;
}
@@ -752,12 +753,8 @@ struct ast_variable *ast_variable_list_from_quoted_string(const char *input, con
}
item_value = ast_strsep_quoted(&item, nv_sep, quote, AST_STRSEP_ALL);
if (!item_value) {
ast_variables_destroy(new_list);
return NULL;
}
new_var = ast_variable_new(item_name, item_value, "");
new_var = ast_variable_new(item_name, item_value ?: "", "");
if (!new_var) {
ast_variables_destroy(new_list);
return NULL;