Fix session.get procedure with undefined keys attribute
authorJo-Philipp Wich <jow@openwrt.org>
Thu, 30 May 2013 12:58:30 +0000 (14:58 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Thu, 30 May 2013 12:58:30 +0000 (14:58 +0200)
session.c

index 9c2b35d7dcd85e93eae0666a768d26caef6c1e49..6352354870bfee081cc50038021c9f011d3fa260 100644 (file)
--- a/session.c
+++ b/session.c
@@ -525,24 +525,22 @@ rpc_handle_get(struct ubus_context *ctx, struct ubus_object *obj,
        blob_buf_init(&buf, 0);
        c = blobmsg_open_table(&buf, "values");
 
-       if (!tb[RPC_SG_KEYS]) {
-               rpc_session_dump_data(ses, &buf);
-               return 0;
-       }
-
-       blobmsg_for_each_attr(attr, tb[RPC_SG_KEYS], rem) {
-               if (blob_id(attr) != BLOBMSG_TYPE_STRING)
-                       continue;
+       if (tb[RPC_SG_KEYS])
+               blobmsg_for_each_attr(attr, tb[RPC_SG_KEYS], rem) {
+                       if (blob_id(attr) != BLOBMSG_TYPE_STRING)
+                               continue;
 
-               data = avl_find_element(&ses->data, blobmsg_data(attr), data, avl);
-               if (!data)
-                       continue;
+                       data = avl_find_element(&ses->data, blobmsg_data(attr), data, avl);
+                       if (!data)
+                               continue;
 
-               blobmsg_add_field(&buf, blobmsg_type(data->attr),
-                                 blobmsg_name(data->attr),
-                                 blobmsg_data(data->attr),
-                                 blobmsg_data_len(data->attr));
-       }
+                       blobmsg_add_field(&buf, blobmsg_type(data->attr),
+                                         blobmsg_name(data->attr),
+                                         blobmsg_data(data->attr),
+                                         blobmsg_data_len(data->attr));
+               }
+       else
+               rpc_session_dump_data(ses, &buf);
 
        blobmsg_close_table(&buf, c);
        ubus_send_reply(ctx, req, buf.head);