storage: ensure SSID strings are NULL-terminated

SSID_MAX_LEN is set at 32, which is the maximum allowed size of a SSID.
The strings holding SSIDs were set at that same size, which does not
allow for proper string termination.

Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
This commit is contained in:
Eneas U de Queiroz 2021-07-06 17:42:03 -03:00 committed by Polynomdivision
parent 8ce09d64de
commit a22f5a79d6
4 changed files with 5 additions and 5 deletions

View file

@ -227,7 +227,7 @@ typedef struct ap_s {
uint32_t channel_utilization; // eval_probe_metric()
time_t time; // remove_old...entries
uint32_t station_count; // compare_station_count() <- better_ap_available()
uint8_t ssid[SSID_MAX_LEN]; // compare_sid() < -better_ap_available()
uint8_t ssid[SSID_MAX_LEN + 1]; // compare_sid() < -better_ap_available()
char neighbor_report[NEIGHBOR_REPORT_LEN];
uint32_t collision_domain; // TODO: ap_get_collision_count() never evaluated?
uint32_t bandwidth; // TODO: Never evaluated?

View file

@ -697,7 +697,7 @@ static int consume_actions(int argc, char* argv[], int harness_verbosity)
ap0->time = faketime;
ap0->station_count = 0;
memset(ap0->ssid, '*', SSID_MAX_LEN);
ap0->ssid[SSID_MAX_LEN - 1] = '\0';
ap0->ssid[SSID_MAX_LEN] = '\0';
ap0->neighbor_report[0] = 0;
ap0->collision_domain = 0;
ap0->bandwidth = 0;

View file

@ -281,8 +281,7 @@ int get_ssid(const char *ifname, char* ssid, size_t ssidmax) {
if (iw->ssid(ifname, buf))
memset(buf, 0, sizeof(buf));
memcpy(ssid, buf, ssidmax);
strcpy(ssid, buf);
strncpy(ssid, buf, ssidmax);
iwinfo_finish();
return 0;
}

View file

@ -96,7 +96,7 @@ struct hostapd_sock_entry {
char iface_name[MAX_INTERFACE_NAME];
char hostname[HOST_NAME_MAX];
struct dawn_mac bssid_addr;
char ssid[SSID_MAX_LEN];
char ssid[SSID_MAX_LEN + 1];
uint8_t ht_support;
uint8_t vht_support;
uint64_t last_channel_time;
@ -1214,6 +1214,7 @@ bool subscribe(struct hostapd_sock_entry *hostapd_entry) {
get_bssid(hostapd_entry->iface_name, hostapd_entry->bssid_addr.u8);
get_ssid(hostapd_entry->iface_name, hostapd_entry->ssid, (SSID_MAX_LEN) * sizeof(char));
hostapd_entry->ssid[SSID_MAX_LEN] = '\0';
hostapd_entry->ht_support = (uint8_t) support_ht(hostapd_entry->iface_name);
hostapd_entry->vht_support = (uint8_t) support_vht(hostapd_entry->iface_name);