From d8cf5cbfc9862d9187d9b15d12f7be523b757791 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 25 Oct 2020 21:32:57 +0100 Subject: fix #6525: handle explicit null in JSON nicely --- src/include/gnunet_json_lib.h | 2 +- src/json/json.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h index 92597d3dd..3dc79105e 100644 --- a/src/include/gnunet_json_lib.h +++ b/src/include/gnunet_json_lib.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet - Copyright (C) 2014, 2015, 2016 GNUnet e.V. + Copyright (C) 2014, 2015, 2016, 2020 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published diff --git a/src/json/json.c b/src/json/json.c index 0631c51bb..503702962 100644 --- a/src/json/json.c +++ b/src/json/json.c @@ -56,11 +56,17 @@ GNUNET_JSON_parse (const json_t *root, if (NULL == spec[i].field) pos = (json_t *) root; else - pos = json_object_get (root, spec[i].field); - if ((NULL == pos) && (spec[i].is_optional)) + pos = json_object_get (root, + spec[i].field); + if ( ( (NULL == pos) || + (json_is_null (pos) ) ) && + (spec[i].is_optional) ) continue; - if ((NULL == pos) || - (GNUNET_OK != spec[i].parser (spec[i].cls, pos, &spec[i]))) + if ( (NULL == pos) || + (GNUNET_OK != + spec[i].parser (spec[i].cls, + pos, + &spec[i])) ) { if (NULL != error_json_name) *error_json_name = spec[i].field; -- cgit v1.2.3