Skip to content

Commit

Permalink
rest: Don't touch intermediary boxes or martialed boxes directly, use…
Browse files Browse the repository at this point in the history
… the assignment functions
  • Loading branch information
arr2036 committed May 23, 2020
1 parent 321bf76 commit 7e5a27d
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/modules/rlm_rest/rest.c
Expand Up @@ -878,14 +878,12 @@ static VALUE_PAIR *json_pair_alloc_leaf(UNUSED rlm_rest_t const *instance, UNUSE
switch (json_object_get_type(leaf)) {
case json_type_int:
if (flags->do_xlat) RWDEBUG("Ignoring do_xlat on 'int', attribute \"%s\"", da->name);
src.vb_int32 = json_object_get_int(leaf);
src.type = FR_TYPE_INT32;
fr_value_box_shallow(&src, (int32_t)json_object_get_int(leaf), true);
break;

case json_type_double:
if (flags->do_xlat) RWDEBUG("Ignoring do_xlat on 'double', attribute \"%s\"", da->name);
src.vb_float64 = json_object_get_double(leaf);
src.type = FR_TYPE_FLOAT64;
fr_value_box_shallow(&src, (double)json_object_get_double(leaf), true);
break;

case json_type_string:
Expand All @@ -895,32 +893,32 @@ static VALUE_PAIR *json_pair_alloc_leaf(UNUSED rlm_rest_t const *instance, UNUSE
talloc_free(vp);
return NULL;
}
src.vb_strvalue = expanded;
src.datum.length = talloc_array_length(src.vb_strvalue) - 1;
fr_value_box_bstrndup_shallow(&src, NULL, expanded,
talloc_array_length(expanded) - 1, true);
} else {
src.vb_strvalue = value;
src.datum.length = json_object_get_string_len(leaf);
fr_value_box_bstrndup_shallow(&src, NULL, value,
json_object_get_string_len(leaf), true);
}
src.type = FR_TYPE_STRING;

break;

default:
{
char const *str;
if (flags->do_xlat) RWDEBUG("Ignoring do_xlat on 'object', attribute \"%s\"", da->name);

/*
* Should encode any nested JSON structures into JSON strings.
*
* "I knew you liked JSON so I put JSON in your JSON!"
*/
src.vb_strvalue = json_object_get_string(leaf);
if (!src.vb_strvalue) {
str = json_object_get_string(leaf);
if (!str) {
RWDEBUG("Failed getting string value for attribute \"%s\" (skipping)", da->name);
talloc_free(vp);
return NULL;
}
src.type = FR_TYPE_STRING;
src.datum.length = strlen(src.vb_strvalue);
fr_value_box_strdup_shallow(&src, NULL, str, true);
}
}

ret = fr_value_box_cast(vp, &vp->data, da->type, da, &src);
Expand Down

0 comments on commit 7e5a27d

Please sign in to comment.