From 97384dd72acbba1e586824b477c2bea483505a40 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 12 Aug 2013 14:49:02 +0200 Subject: [PATCH] uci: refactor revert code to avoid illegal pointer access --- uci.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/uci.c b/uci.c index 0409a07..ac97cbd 100644 --- 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(); } -- 2.11.0