When parsing DBus messages to Nameservers.Configuration, check all
space-separated strings, replace non-IPs with empty strings and
remove all empty strings from input.

Sending "123.123.123.123  invalid-ip 8.8.8.8 " will result in
Nameservers.Configuration containing [ 123.123.123.123, 8.8.8.8 ],
rather than [ 123.123.123.123, , invalid-ip, 8.8.8.8, ].

Previously the function only checked that the string starts with a
correct IP and then split the string with spaces as delimiter, thus
accepting bad values.
---
 src/service.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/service.c b/src/service.c
index 8ea7c7c..76099f1 100644
--- a/src/service.c
+++ b/src/service.c
@@ -3272,20 +3272,30 @@ static DBusMessage *set_property(DBusConnection *conn,
                        const char *val;
                        dbus_message_iter_get_basic(&entry, &val);
                        dbus_message_iter_next(&entry);
-                       if (connman_inet_check_ipaddress(val) > 0) {
-                               if (str->len > 0)
-                                       g_string_append_printf(str, " %s", val);
-                               else
-                                       g_string_append(str, val);
-                       }
+
+                       if (!val[0])
+                               continue;
+
+                       if (str->len > 0)
+                               g_string_append_printf(str, " %s", val);
+                       else
+                               g_string_append(str, val);
                }
 
                nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
                g_strfreev(service->nameservers_config);
 
                if (str->len > 0) {
-                       service->nameservers_config =
-                               g_strsplit_set(str->str, " ", 0);
+                       char **nameservers, **iter;
+
+                       nameservers = g_strsplit_set(str->str, " ", 0);
+
+                       for (iter = nameservers; *iter; iter++)
+                               if (connman_inet_check_ipaddress(*iter) <= 0)
+                                       *iter[0] = '\0';
+
+                       nameservers = remove_empty_strings(nameservers);
+                       service->nameservers_config = nameservers;
                } else {
                        service->nameservers_config = NULL;
                }
-- 
2.1.0

_______________________________________________
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman

Reply via email to