From a4dec0d88c144d0e973c1884531e27c7499c27a2 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 10 Jul 2014 11:03:13 +0200 Subject: [PATCH] ubus: fix fw3_ubus_device() to only return a pointer if a device was found Signed-off-by: Jo-Philipp Wich --- ubus.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ubus.c b/ubus.c index 581f51c..8e5e60e 100644 --- a/ubus.c +++ b/ubus.c @@ -140,18 +140,13 @@ fw3_ubus_device(const char *net) struct fw3_device *dev = NULL; struct blob_attr *tb[__DEV_MAX]; struct blob_attr *cur; + char *name = NULL; int rem; if (!net || !interfaces) return NULL; - dev = calloc(1, sizeof(*dev)); - if (!dev) - return NULL; - blobmsg_for_each_attr(cur, interfaces, rem) { - char *name; - blobmsg_parse(policy, __DEV_MAX, tb, blobmsg_data(cur), blobmsg_len(cur)); if (!tb[DEV_INTERFACE] || strcmp(blobmsg_data(tb[DEV_INTERFACE]), net) != 0) @@ -164,12 +159,21 @@ fw3_ubus_device(const char *net) else continue; - snprintf(dev->name, sizeof(dev->name), "%s", name); - dev->set = !!dev->name[0]; - return dev; + break; } - return NULL; + if (!name) + return NULL; + + dev = calloc(1, sizeof(*dev)); + + if (!dev) + return NULL; + + snprintf(dev->name, sizeof(dev->name), "%s", name); + dev->set = true; + + return dev; } void -- 2.25.1