summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjobol <jose.bollo@iot.bzh>2018-05-14 11:36:22 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 14:12:02 +0100
commitdddab2901df5ae7129e245407436ecfc90c2116d (patch)
treeba791a7238179f76221dd2e850d5826e480e8da8
parentbfb135e978673215dc9045d5d26106b613fc84c8 (diff)
wrap-json: Accept null as valid base64
Signed-off-by: jobol <jose.bollo@iot.bzh>
-rw-r--r--wrap-json.c27
1 files changed, 18 insertions, 9 deletions
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]);