From 4899dda4afcec526e7f2237bec9f2c8746d28a55 Mon Sep 17 00:00:00 2001 From: lemoer Date: Thu, 21 Sep 2017 20:56:40 +0200 Subject: [PATCH] treewide: check for NULL after uci_alloc_context() (#1224) --- package/gluon-autoupdater/src/respondd.c | 2 ++ package/gluon-mesh-batman-adv/src/respondd.c | 2 ++ package/gluon-mesh-vpn-fastd/src/respondd.c | 6 +++++- package/gluon-node-info/src/respondd.c | 2 ++ package/gluon-respondd/src/respondd.c | 2 ++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/package/gluon-autoupdater/src/respondd.c b/package/gluon-autoupdater/src/respondd.c index 66b7a928..74468fb1 100644 --- a/package/gluon-autoupdater/src/respondd.c +++ b/package/gluon-autoupdater/src/respondd.c @@ -36,6 +36,8 @@ static struct json_object * get_autoupdater(void) { struct uci_context *ctx = uci_alloc_context(); + if (!ctx) + return NULL; ctx->flags &= ~UCI_FLAG_STRICT; struct uci_package *p; diff --git a/package/gluon-mesh-batman-adv/src/respondd.c b/package/gluon-mesh-batman-adv/src/respondd.c index 60df1523..ae42a153 100644 --- a/package/gluon-mesh-batman-adv/src/respondd.c +++ b/package/gluon-mesh-batman-adv/src/respondd.c @@ -446,6 +446,8 @@ static void count_iface_stations(size_t *wifi24, size_t *wifi5, const char *ifna static void count_stations(size_t *wifi24, size_t *wifi5) { struct uci_context *ctx = uci_alloc_context(); + if (!ctx) + return; ctx->flags &= ~UCI_FLAG_STRICT; diff --git a/package/gluon-mesh-vpn-fastd/src/respondd.c b/package/gluon-mesh-vpn-fastd/src/respondd.c index 87d69e07..2103dff7 100644 --- a/package/gluon-mesh-vpn-fastd/src/respondd.c +++ b/package/gluon-mesh-vpn-fastd/src/respondd.c @@ -77,6 +77,8 @@ static struct json_object * get_fastd(void) { bool enabled = false; struct uci_context *ctx = uci_alloc_context(); + if (!ctx) + goto disabled_nofree; ctx->flags &= ~UCI_FLAG_STRICT; struct uci_package *p; @@ -92,8 +94,8 @@ static struct json_object * get_fastd(void) { enabled = true; disabled: - uci_free_context(ctx); + disabled_nofree: struct json_object *ret = json_object_new_object(); json_object_object_add(ret, "version", get_fastd_version()); @@ -159,6 +161,8 @@ static struct json_object * get_status(void) { struct json_object *ret = NULL; struct uci_context *ctx = uci_alloc_context(); + if (!ctx) + return NULL; ctx->flags &= ~UCI_FLAG_STRICT; struct uci_package *p; diff --git a/package/gluon-node-info/src/respondd.c b/package/gluon-node-info/src/respondd.c index 3b0e07dc..7d5e2edf 100644 --- a/package/gluon-node-info/src/respondd.c +++ b/package/gluon-node-info/src/respondd.c @@ -117,6 +117,8 @@ static struct json_object * respondd_provider_nodeinfo(void) { struct json_object *ret = json_object_new_object(); struct uci_context *ctx = uci_alloc_context(); + if (!ctx) + return ret; ctx->flags &= ~UCI_FLAG_STRICT; struct uci_package *p; diff --git a/package/gluon-respondd/src/respondd.c b/package/gluon-respondd/src/respondd.c index bb54f382..a31693e6 100644 --- a/package/gluon-respondd/src/respondd.c +++ b/package/gluon-respondd/src/respondd.c @@ -70,6 +70,8 @@ static struct json_object * get_hostname(void) { struct json_object *ret = NULL; struct uci_context *ctx = uci_alloc_context(); + if (!ctx) + return NULL; ctx->flags &= ~UCI_FLAG_STRICT; char section[] = "system.@system[0]";