rpcd-mod-luci: fix crash on not existing uci options
authorJo-Philipp Wich <jo@mein.io>
Sat, 2 Nov 2019 19:13:00 +0000 (20:13 +0100)
committerJo-Philipp Wich <jo@mein.io>
Sat, 2 Nov 2019 19:14:25 +0000 (20:14 +0100)
Checking the return value of uci_lookup_ptr() is not enough to ensure that
the requested optiomn has actually been found.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
libs/rpcd-mod-luci/src/luci.c

index 04d3a15b7b125f7e2d610d2e0a80a847f24f3b63..245ca636bede0eb55db059819d1381ad17a7bafd 100644 (file)
@@ -359,7 +359,7 @@ find_leasefile(struct uci_context *uci, const char *section)
                ptr.option = "leasefile";
                ptr.o = NULL;
 
-               if (uci_lookup_ptr(uci, &ptr, NULL, true))
+               if (uci_lookup_ptr(uci, &ptr, NULL, true) || ptr.o == NULL)
                        continue;
 
                if (ptr.o->type != UCI_TYPE_STRING)
@@ -1254,7 +1254,7 @@ rpc_luci_get_host_hints_uci(struct reply_context *rctx)
                ptr.option = "ip";
                ptr.o = NULL;
 
-               if (uci_lookup_ptr(uci, &ptr, NULL, true))
+               if (uci_lookup_ptr(uci, &ptr, NULL, true) || ptr.o == NULL)
                        continue;
 
                if (ptr.o->type != UCI_TYPE_STRING)
@@ -1266,7 +1266,7 @@ rpc_luci_get_host_hints_uci(struct reply_context *rctx)
                ptr.option = "name";
                ptr.o = NULL;
 
-               if (!uci_lookup_ptr(uci, &ptr, NULL, true) &&
+               if (!uci_lookup_ptr(uci, &ptr, NULL, true) && ptr.o != NULL &&
                    ptr.o->type == UCI_TYPE_STRING)
                    n = ptr.o->v.string;
                else
@@ -1275,7 +1275,7 @@ rpc_luci_get_host_hints_uci(struct reply_context *rctx)
                ptr.option = "mac";
                ptr.o = NULL;
 
-               if (uci_lookup_ptr(uci, &ptr, NULL, true))
+               if (uci_lookup_ptr(uci, &ptr, NULL, true) || ptr.o == NULL)
                        continue;
 
                if (ptr.o->type == UCI_TYPE_STRING) {