uci: refactor revert code to avoid illegal pointer access
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 12 Aug 2013 12:49:02 +0000 (14:49 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Mon, 12 Aug 2013 12:50:09 +0000 (14:50 +0200)
uci.c

diff --git a/uci.c b/uci.c
index 0409a07d72927d41f9a066cb6b8441a2943acb07..ac97cbdd4231a74805768f6b98594673bea7a5d4 100644 (file)
--- a/uci.c
+++ b/uci.c
@@ -1021,19 +1021,22 @@ rpc_uci_revert_commit(struct blob_attr *msg, bool commit)
                return UBUS_STATUS_PERMISSION_DENIED;
 
        ptr.package = blobmsg_data(tb[RPC_C_CONFIG]);
-       uci_load(cursor, ptr.package, &p);
-
-       if (!p || uci_lookup_ptr(cursor, &ptr, NULL, true) || !ptr.p)
-               goto out;
 
        if (commit)
-               uci_commit(cursor, &p, false);
-       else
-               uci_revert(cursor, &ptr);
+       {
+               uci_load(cursor, ptr.package, &p);
 
-out:
-       if (p)
-               uci_unload(cursor, p);
+               if (p)
+               {
+                       uci_commit(cursor, &p, false);
+                       uci_unload(cursor, p);
+               }
+       }
+       else
+       {
+               if (!uci_lookup_ptr(cursor, &ptr, NULL, true) && ptr.p)
+                       uci_revert(cursor, &ptr);
+       }
 
        return rpc_uci_status();
 }