From dddab2901df5ae7129e245407436ecfc90c2116d Mon Sep 17 00:00:00 2001 From: jobol Date: Mon, 14 May 2018 11:36:22 +0200 Subject: wrap-json: Accept null as valid base64 Signed-off-by: jobol --- wrap-json.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'wrap-json.c') diff --git a/wrap-json.c b/wrap-json.c index 11fdd8c..6978c25 100644 --- a/wrap-json.c +++ b/wrap-json.c @@ -665,15 +665,22 @@ static int vunpack(struct json_object *object, const char *desc, va_list args, i pz = va_arg(args, size_t *); } if (!ignore) { - if (!json_object_is_type(obj, json_type_string)) - goto missfit; - if (store && py && pz) { - rc = decode_base64( - json_object_get_string(obj), - (size_t)json_object_get_string_len(obj), - py, pz, c == 'y'); - if (rc) - goto error; + if (obj == NULL) { + if (store && py && pz) { + *py = NULL; + *pz = 0; + } + } else { + if (!json_object_is_type(obj, json_type_string)) + goto missfit; + if (store && py && pz) { + rc = decode_base64( + json_object_get_string(obj), + (size_t)json_object_get_string_len(obj), + py, pz, c == 'y'); + if (rc) + goto error; + } } } break; @@ -1133,6 +1140,8 @@ int main() U("{\"foo\":42}", "{s?isi!}", "baz", &xi[0], "foo", &xi[1]); U("\"Pz8_Pz8_P2hlbGxvPj4-Pj4-Pg\"", "y", &xy[0], &xz[0]); + U("\"\"", "y", &xy[0], &xz[0]); + U("null", "y", &xy[0], &xz[0]); U("{\"foo\":\"Pz8_Pz8_P2hlbGxvPj4-Pj4-Pg\"}", "{s?y}", "foo", &xy[0], &xz[0]); U("{\"foo\":\"\"}", "{s?y}", "foo", &xy[0], &xz[0]); U("{}", "{s?y}", "foo", &xy[0], &xz[0]); -- cgit 1.2.3-korg