options: fix fw3_parse_network() when destination pointer is not a list
authorJo-Philipp Wich <jow@openwrt.org>
Thu, 3 Jul 2014 08:52:48 +0000 (10:52 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Thu, 3 Jul 2014 09:01:15 +0000 (11:01 +0200)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
options.c

index e864db7ca3c3a12c9edeb0a87cf1ff5af60036c4..25668fcec9ef4addd3f5012b4d894b00211a6d91 100644 (file)
--- a/options.c
+++ b/options.c
@@ -329,7 +329,7 @@ bool
 fw3_parse_network(void *ptr, const char *val, bool is_list)
 {
        struct fw3_device dev = { };
-       struct fw3_address *addr;
+       struct fw3_address *addr, *tmp;
        LIST_HEAD(addr_list);
 
        if (!fw3_parse_address(ptr, val, is_list))
@@ -343,7 +343,19 @@ fw3_parse_network(void *ptr, const char *val, bool is_list)
                        addr->invert = dev.invert;
                        addr->resolved = true;
                }
-               list_splice_tail(&addr_list, ptr);
+
+               if (is_list)
+               {
+                       list_splice_tail(&addr_list, ptr);
+               }
+               else if (!list_empty(&addr_list))
+               {
+                       memcpy(ptr, list_first_entry(&addr_list, typeof(*addr), list),
+                              sizeof(*addr));
+
+                       list_for_each_entry_safe(addr, tmp, &addr_list, list)
+                               free(addr);
+               }
        }
 
        return true;