Commit 898de5d1dd for freeswitch.com
commit 898de5d1dd30bb7f6ec7fcd962abf1419f6b562a
Author: Dmitry Verenitsin <morbit85@gmail.com>
Date: Wed Nov 18 19:40:18 2026 +0500
[mod_verto] Skip unnamed elements when reading client JSON members
`check_auth()` and `parse_user_vars()` copy the members of
`loginParams` and `userVariables` into events and channel variables,
but validated the member name on the string-value branch only. Check
it once at the top of each loop so every value type is handled the
same way.
diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c
index e95d63f96a..fe935bcd0f 100644
--- a/src/mod/endpoints/mod_verto/mod_verto.c
+++ b/src/mod/endpoints/mod_verto/mod_verto.c
@@ -1077,11 +1077,16 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
cJSON * i;
for(i = json_ptr->child; i; i = i->next) {
+ /* Skip empty names, and the NULL ones cJSON gives array elements. */
+ if (zstr(i->string)) {
+ continue;
+ }
+
if (i->type == cJSON_True) {
switch_event_add_header_string(req_params, SWITCH_STACK_BOTTOM, i->string, "true");
} else if (i->type == cJSON_False) {
switch_event_add_header_string(req_params, SWITCH_STACK_BOTTOM, i->string, "false");
- } else if (!zstr(i->string) && !zstr(i->valuestring)) {
+ } else if (!zstr(i->valuestring)) {
switch_event_add_header_string(req_params, SWITCH_STACK_BOTTOM, i->string, i->valuestring);
}
}
@@ -1153,11 +1158,16 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
switch_mutex_lock(jsock->flag_mutex);
for (i = json_ptr->child; i; i = i->next) {
+ /* Skip empty names, and the NULL ones cJSON gives array elements. */
+ if (zstr(i->string)) {
+ continue;
+ }
+
if (i->type == cJSON_True) {
switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, "true");
} else if (i->type == cJSON_False) {
switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, "false");
- } else if (!zstr(i->string) && !zstr(i->valuestring)) {
+ } else if (!zstr(i->valuestring)) {
switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, i->valuestring);
}
}
@@ -3811,13 +3821,20 @@ static void parse_user_vars(cJSON *obj, switch_core_session_t *session)
cJSON * i;
for(i = json_ptr->child; i; i = i->next) {
- char *varname = switch_core_session_sprintf(session, "verto_dvar_%s", i->string);
+ char *varname;
+
+ /* Skip empty names, and the NULL ones cJSON gives array elements. */
+ if (zstr(i->string)) {
+ continue;
+ }
+
+ varname = switch_core_session_sprintf(session, "verto_dvar_%s", i->string);
if (i->type == cJSON_True) {
switch_channel_set_variable(channel, varname, "true");
} else if (i->type == cJSON_False) {
switch_channel_set_variable(channel, varname, "false");
- } else if (!zstr(i->string) && !zstr(i->valuestring)) {
+ } else if (!zstr(i->valuestring)) {
switch_channel_set_variable(channel, varname, i->valuestring);
}
}