Skip to content

Commit f3e235f

Browse files
committed
sd-netlink, wifi-util: fix attribute type of NL80211_ATTR_SSID
1 parent ae2b86d commit f3e235f

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/basic/missing_network.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@
4444
#ifndef BOND_MAX_ARP_TARGETS
4545
#define BOND_MAX_ARP_TARGETS 16
4646
#endif
47+
48+
/* Not exposed but defined in include/linux/ieee80211.h */
49+
#ifndef IEEE80211_MAX_SSID_LEN
50+
#define IEEE80211_MAX_SSID_LEN 32
51+
#endif

src/libsystemd/sd-netlink/netlink-types-genl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/nl80211.h>
1212
#include <linux/wireguard.h>
1313

14+
#include "missing_network.h"
1415
#include "netlink-genl.h"
1516
#include "netlink-types-internal.h"
1617

@@ -181,7 +182,7 @@ static const NLType genl_macsec_types[] = {
181182
static const NLType genl_nl80211_types[] = {
182183
[NL80211_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 },
183184
[NL80211_ATTR_MAC] = { .type = NETLINK_TYPE_ETHER_ADDR },
184-
[NL80211_ATTR_SSID] = { .type = NETLINK_TYPE_STRING },
185+
[NL80211_ATTR_SSID] = { .type = NETLINK_TYPE_BINARY, .size = IEEE80211_MAX_SSID_LEN },
185186
[NL80211_ATTR_IFTYPE] = { .type = NETLINK_TYPE_U32 },
186187
};
187188

src/shared/wifi-util.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *ret_i
99
_cleanup_free_ char *ssid = NULL;
1010
const char *family;
1111
uint32_t iftype;
12+
size_t len;
1213
int r;
1314

1415
assert(genl);
@@ -53,9 +54,18 @@ int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *ret_i
5354
if (r < 0)
5455
return log_debug_errno(r, "Failed to get NL80211_ATTR_IFTYPE attribute: %m");
5556

56-
r = sd_netlink_message_read_string_strdup(reply, NL80211_ATTR_SSID, &ssid);
57+
r = sd_netlink_message_read_data_suffix0(reply, NL80211_ATTR_SSID, &len, (void**) &ssid);
5758
if (r < 0 && r != -ENODATA)
5859
return log_debug_errno(r, "Failed to get NL80211_ATTR_SSID attribute: %m");
60+
if (r >= 0) {
61+
if (len == 0) {
62+
log_debug("SSID has zero length, ignoring the received SSID.");
63+
ssid = mfree(ssid);
64+
} else if (strlen_ptr(ssid) != len) {
65+
log_debug("SSID contains NUL character(s), ignoring the received SSID.");
66+
ssid = mfree(ssid);
67+
}
68+
}
5969

6070
if (ret_iftype)
6171
*ret_iftype = iftype;

0 commit comments

Comments
 (0)