Skip to content

Commit

Permalink
Avoid calling json_object_array_get_idx on non-array objects, bad thi…
Browse files Browse the repository at this point in the history
…ngs happen...
  • Loading branch information
arr2036 committed Mar 17, 2014
1 parent 0fe5083 commit 432cfe1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/modules/rlm_rest/rest.c
Expand Up @@ -1146,7 +1146,7 @@ static int json_pairmake(rlm_rest_t *instance, UNUSED rlm_rest_section_t *sectio
char const *p;
char *q;

int i, elements;
int i = 0, elements;
struct json_object *value, *element, *tmp;

char const *name;
Expand Down Expand Up @@ -1273,8 +1273,7 @@ static int json_pairmake(rlm_rest_t *instance, UNUSED rlm_rest_section_t *sectio
* A JSON 'value' key, may have multiple elements, iterate
* over each of them, creating a new VALUE_PAIR.
*/
for (i = 0; i < elements; element = json_object_array_get_idx(value, ++i))
{
do {
if (max_attrs-- <= 0) {
RWDEBUG("At maximum attribute limit");
return max;
Expand All @@ -1287,7 +1286,7 @@ static int json_pairmake(rlm_rest_t *instance, UNUSED rlm_rest_section_t *sectio
flags.op = T_OP_ADD;
}

if (json_object_is_type(value, json_type_object) && !flags.is_json) {
if (json_object_is_type(element, json_type_object) && !flags.is_json) {
/* TODO: Insert nested VP into VP structure...*/
RWDEBUG("Found nested VP, these are not yet supported, skipping...");

Expand All @@ -1303,7 +1302,11 @@ static int json_pairmake(rlm_rest_t *instance, UNUSED rlm_rest_section_t *sectio
}

radius_pairmove(current, vps, vp);
}
/*
* If we call json_object_array_get_idx on something that's not an array
* the behaviour appears to be to occasionally segfault.
*/
} while ((++i < elements) && (element = json_object_array_get_idx(value, i)));
}

return max - max_attrs;
Expand Down

0 comments on commit 432cfe1

Please sign in to comment.