mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-01-03 10:32:33 +01:00
network: Use const char * to represent ssid
This also fixes a potential buffer overflow since the ssid was cast to a string inside network_create. However, ssid is a buffer of 32 bytes, and would not be null-terminated in the case of a 32-byte SSID.
This commit is contained in:
parent
12fca8b7f7
commit
29d5eeb3ca
14
src/device.c
14
src/device.c
@ -105,7 +105,7 @@ void __iwd_device_foreach(iwd_device_foreach_func func, void *user_data)
|
||||
}
|
||||
|
||||
static const char *iwd_network_get_path(struct device *device,
|
||||
const uint8_t *ssid, size_t ssid_len,
|
||||
const char *ssid,
|
||||
enum security security)
|
||||
{
|
||||
static char path[256];
|
||||
@ -113,7 +113,7 @@ static const char *iwd_network_get_path(struct device *device,
|
||||
|
||||
pos = snprintf(path, sizeof(path), "%s/", device_get_path(device));
|
||||
|
||||
for (i = 0; i < ssid_len && pos < sizeof(path); i++)
|
||||
for (i = 0; ssid[i] && pos < sizeof(path); i++)
|
||||
pos += snprintf(path + pos, sizeof(path) - pos, "%02x",
|
||||
ssid[i]);
|
||||
|
||||
@ -222,6 +222,7 @@ static void process_bss(struct device *device, struct scan_bss *bss,
|
||||
const char *path;
|
||||
double rankmod;
|
||||
struct autoconnect_entry *entry;
|
||||
char ssid[33];
|
||||
|
||||
l_debug("Found BSS '%s' with SSID: %s, freq: %u, rank: %u, "
|
||||
"strength: %i",
|
||||
@ -234,6 +235,9 @@ static void process_bss(struct device *device, struct scan_bss *bss,
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(ssid, bss->ssid, bss->ssid_len);
|
||||
ssid[bss->ssid_len] = '\0';
|
||||
|
||||
/*
|
||||
* If both an RSN and a WPA elements are present currently
|
||||
* RSN takes priority and the WPA IE is ignored.
|
||||
@ -270,13 +274,11 @@ static void process_bss(struct device *device, struct scan_bss *bss,
|
||||
} else
|
||||
security = scan_get_security(bss->capability, NULL);
|
||||
|
||||
path = iwd_network_get_path(device, bss->ssid, bss->ssid_len,
|
||||
security);
|
||||
path = iwd_network_get_path(device, ssid, security);
|
||||
|
||||
network = l_hashmap_lookup(device->networks, path);
|
||||
if (!network) {
|
||||
network = network_create(device, bss->ssid, bss->ssid_len,
|
||||
security);
|
||||
network = network_create(device, ssid, security);
|
||||
|
||||
if (!network_register(network, path)) {
|
||||
network_remove(network, -EINVAL);
|
||||
|
@ -278,15 +278,14 @@ static void network_info_put(struct network_info *network)
|
||||
network_info_free(network);
|
||||
}
|
||||
|
||||
struct network *network_create(struct device *device,
|
||||
uint8_t *ssid, uint8_t ssid_len,
|
||||
struct network *network_create(struct device *device, const char *ssid,
|
||||
enum security security)
|
||||
{
|
||||
struct network *network;
|
||||
|
||||
network = l_new(struct network, 1);
|
||||
network->device = device;
|
||||
network->info = network_info_get((char *) ssid, security);
|
||||
network->info = network_info_get(ssid, security);
|
||||
|
||||
network->bss_list = l_queue_new();
|
||||
|
||||
|
@ -32,8 +32,7 @@ bool network_connected(struct network *network);
|
||||
void network_disconnected(struct network *network);
|
||||
bool network_rankmod(const struct network *network, double *rankmod);
|
||||
|
||||
struct network *network_create(struct device *device,
|
||||
uint8_t *ssid, uint8_t ssid_len,
|
||||
struct network *network_create(struct device *device, const char *ssid,
|
||||
enum security security);
|
||||
|
||||
const char *network_get_ssid(const struct network *network);
|
||||
|
Loading…
Reference in New Issue
Block a user