From 7e5a27d15b156eb3e885d6e0c75766a41d4992dc Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Sat, 23 May 2020 12:09:18 -0500 Subject: [PATCH] rest: Don't touch intermediary boxes or martialed boxes directly, use the assignment functions --- src/modules/rlm_rest/rest.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/modules/rlm_rest/rest.c b/src/modules/rlm_rest/rest.c index d1b80cf29467..6ff3ef9ebc93 100644 --- a/src/modules/rlm_rest/rest.c +++ b/src/modules/rlm_rest/rest.c @@ -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: @@ -895,17 +893,17 @@ 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); /* @@ -913,14 +911,14 @@ static VALUE_PAIR *json_pair_alloc_leaf(UNUSED rlm_rest_t const *instance, UNUSE * * "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);