]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-netlink, wifi-util: fix attribute type of NL80211_ATTR_SSID
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 21 Sep 2021 17:30:03 +0000 (02:30 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 29 Sep 2021 06:38:59 +0000 (15:38 +0900)
src/basic/missing_network.h
src/libsystemd/sd-netlink/netlink-types-genl.c
src/shared/wifi-util.c

index 24017df87103762c72a1534843d117e384b6afad..6e71b26afd09eeb211578592d0f1288bd2c98415 100644 (file)
@@ -44,3 +44,8 @@
 #ifndef BOND_MAX_ARP_TARGETS
 #define BOND_MAX_ARP_TARGETS 16
 #endif
+
+/* Not exposed but defined in include/linux/ieee80211.h */
+#ifndef IEEE80211_MAX_SSID_LEN
+#define IEEE80211_MAX_SSID_LEN 32
+#endif
index b2f768181fdcd1f57c9b256c42888801bdcafcd6..5df88c0518d2b7b1839c83c30a72ef5d08c1aa07 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/nl80211.h>
 #include <linux/wireguard.h>
 
+#include "missing_network.h"
 #include "netlink-genl.h"
 #include "netlink-types-internal.h"
 
@@ -181,7 +182,7 @@ static const NLType genl_macsec_types[] = {
 static const NLType genl_nl80211_types[] = {
         [NL80211_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
         [NL80211_ATTR_MAC]     = { .type = NETLINK_TYPE_ETHER_ADDR },
-        [NL80211_ATTR_SSID]    = { .type = NETLINK_TYPE_STRING },
+        [NL80211_ATTR_SSID]    = { .type = NETLINK_TYPE_BINARY, .size = IEEE80211_MAX_SSID_LEN },
         [NL80211_ATTR_IFTYPE]  = { .type = NETLINK_TYPE_U32 },
 };
 
index f94f1744d3b89ee5302f2c41d39ba6bdefd4f9b2..8d6c184be1e2be4f7dbcd787b69f269200da86ac 100644 (file)
@@ -9,6 +9,7 @@ int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *ret_i
         _cleanup_free_ char *ssid = NULL;
         const char *family;
         uint32_t iftype;
+        size_t len;
         int r;
 
         assert(genl);
@@ -53,9 +54,18 @@ int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *ret_i
         if (r < 0)
                 return log_debug_errno(r, "Failed to get NL80211_ATTR_IFTYPE attribute: %m");
 
-        r = sd_netlink_message_read_string_strdup(reply, NL80211_ATTR_SSID, &ssid);
+        r = sd_netlink_message_read_data_suffix0(reply, NL80211_ATTR_SSID, &len, (void**) &ssid);
         if (r < 0 && r != -ENODATA)
                 return log_debug_errno(r, "Failed to get NL80211_ATTR_SSID attribute: %m");
+        if (r >= 0) {
+                if (len == 0) {
+                        log_debug("SSID has zero length, ignoring the received SSID.");
+                        ssid = mfree(ssid);
+                } else if (strlen_ptr(ssid) != len) {
+                        log_debug("SSID contains NUL character(s), ignoring the received SSID.");
+                        ssid = mfree(ssid);
+                }
+        }
 
         if (ret_iftype)
                 *ret_iftype = iftype;