Use SSID_MAX_LEN define instead of value 32 when comparing SSID length

This makes the implementation easier to understand.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
master
Jouni Malinen 9 years ago committed by Jouni Malinen
parent 65b10253d6
commit d9d1b9527a

@ -10,6 +10,7 @@
#include <dirent.h>
#include "common/wpa_ctrl.h"
#include "common/ieee802_11_defs.h"
#include "utils/common.h"
#include "utils/eloop.h"
#include "utils/edit.h"
@ -541,7 +542,7 @@ static int hostapd_cli_cmd_wps_config(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
char buf[256];
char ssid_hex[2 * 32 + 1];
char ssid_hex[2 * SSID_MAX_LEN + 1];
char key_hex[2 * 64 + 1];
int i;
@ -552,7 +553,7 @@ static int hostapd_cli_cmd_wps_config(struct wpa_ctrl *ctrl, int argc,
}
ssid_hex[0] = '\0';
for (i = 0; i < 32; i++) {
for (i = 0; i < SSID_MAX_LEN; i++) {
if (argv[0][i] == '\0')
break;
os_snprintf(&ssid_hex[i * 2], 3, "%02x", argv[0][i]);

@ -10,6 +10,8 @@
#ifndef IEEE802_11_DEFS_H
#define IEEE802_11_DEFS_H
#include <utils/common.h>
/* IEEE 802.11 defines */
#define WLAN_FC_PVER 0x0003

@ -9,6 +9,8 @@
#ifndef PRIVSEP_COMMANDS_H
#define PRIVSEP_COMMANDS_H
#include "common/ieee802_11_defs.h"
enum privsep_cmd {
PRIVSEP_CMD_REGISTER,
PRIVSEP_CMD_UNREGISTER,
@ -29,7 +31,7 @@ enum privsep_cmd {
struct privsep_cmd_associate
{
u8 bssid[ETH_ALEN];
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
size_t ssid_len;
int hwmode;
int freq;

@ -20,6 +20,7 @@
#define WPA_SUPPLICANT_DRIVER_VERSION 4
#include "common/defs.h"
#include "common/ieee802_11_defs.h"
#include "utils/list.h"
#define HOSTAPD_CHAN_DISABLED 0x00000001
@ -341,7 +342,7 @@ struct wpa_driver_scan_params {
* is not needed anymore.
*/
struct wpa_driver_scan_filter {
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
size_t ssid_len;
} *filter_ssids;

@ -192,7 +192,7 @@ struct prism2_hostapd_param {
} mlme;
struct {
u8 ssid_len;
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
} scan_req;
} u;
};

@ -709,11 +709,11 @@ static int wpa_driver_ndis_radio_off(struct wpa_driver_ndis_data *drv)
/* Disconnect by setting SSID to random (i.e., likely not used). */
static int wpa_driver_ndis_disconnect(struct wpa_driver_ndis_data *drv)
{
char ssid[32];
char ssid[SSID_MAX_LEN];
int i;
for (i = 0; i < 32; i++)
for (i = 0; i < SSID_MAX_LEN; i++)
ssid[i] = rand() & 0xff;
return wpa_driver_ndis_set_ssid(drv, (u8 *) ssid, 32);
return wpa_driver_ndis_set_ssid(drv, (u8 *) ssid, SSID_MAX_LEN);
}
@ -806,7 +806,7 @@ static struct wpa_scan_res * wpa_driver_ndis_add_scan_ssid(
if (wpa_scan_get_ie(r, WLAN_EID_SSID))
return r; /* SSID IE already present */
if (ssid->SsidLength == 0 || ssid->SsidLength > 32)
if (ssid->SsidLength == 0 || ssid->SsidLength > SSID_MAX_LEN)
return r; /* No valid SSID inside scan data */
nr = os_realloc(r, sizeof(*r) + r->ie_len + 2 + ssid->SsidLength);

@ -110,7 +110,7 @@ struct wpa_driver_nl80211_data {
u8 bssid[ETH_ALEN];
u8 prev_bssid[ETH_ALEN];
int associated;
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
size_t ssid_len;
enum nl80211_iftype nlmode;
enum nl80211_iftype ap_scan_as_station;
@ -169,7 +169,7 @@ struct wpa_driver_nl80211_data {
/* From failed authentication command */
int auth_freq;
u8 auth_bssid_[ETH_ALEN];
u8 auth_ssid[32];
u8 auth_ssid[SSID_MAX_LEN];
size_t auth_ssid_len;
int auth_alg;
u8 *auth_ie;

@ -281,14 +281,15 @@ static int wpa_driver_privsep_get_ssid(void *priv, u8 *ssid)
{
struct wpa_driver_privsep_data *drv = priv;
int res, ssid_len;
u8 reply[sizeof(int) + 32];
u8 reply[sizeof(int) + SSID_MAX_LEN];
size_t len = sizeof(reply);
res = wpa_priv_cmd(drv, PRIVSEP_CMD_GET_SSID, NULL, 0, reply, &len);
if (res < 0 || len < sizeof(int))
return -1;
os_memcpy(&ssid_len, reply, sizeof(int));
if (ssid_len < 0 || ssid_len > 32 || sizeof(int) + ssid_len > len) {
if (ssid_len < 0 || ssid_len > SSID_MAX_LEN ||
sizeof(int) + ssid_len > len) {
wpa_printf(MSG_DEBUG, "privsep: Invalid get SSID reply");
return -1;
}

@ -132,7 +132,7 @@ int wpa_driver_wext_get_ssid(void *priv, u8 *ssid)
os_memset(&iwr, 0, sizeof(iwr));
os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
iwr.u.essid.pointer = (caddr_t) ssid;
iwr.u.essid.length = 32;
iwr.u.essid.length = SSID_MAX_LEN;
if (ioctl(drv->ioctl_sock, SIOCGIWESSID, &iwr) < 0) {
wpa_printf(MSG_ERROR, "ioctl[SIOCGIWESSID]: %s",
@ -140,8 +140,8 @@ int wpa_driver_wext_get_ssid(void *priv, u8 *ssid)
ret = -1;
} else {
ret = iwr.u.essid.length;
if (ret > 32)
ret = 32;
if (ret > SSID_MAX_LEN)
ret = SSID_MAX_LEN;
/* Some drivers include nul termination in the SSID, so let's
* remove it here before further processing. WE-21 changes this
* to explicitly require the length _not_ to include nul
@ -169,7 +169,7 @@ int wpa_driver_wext_set_ssid(void *priv, const u8 *ssid, size_t ssid_len)
int ret = 0;
char buf[33];
if (ssid_len > 32)
if (ssid_len > SSID_MAX_LEN)
return -1;
os_memset(&iwr, 0, sizeof(iwr));
@ -1199,7 +1199,7 @@ struct wext_scan_data {
struct wpa_scan_res res;
u8 *ie;
size_t ie_len;
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
size_t ssid_len;
int maxrate;
};
@ -1952,7 +1952,7 @@ static void wpa_driver_wext_disconnect(struct wpa_driver_wext_data *drv)
{
struct iwreq iwr;
const u8 null_bssid[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
int i;
/*
@ -1994,9 +1994,9 @@ static void wpa_driver_wext_disconnect(struct wpa_driver_wext_data *drv)
* SIOCSIWMLME commands (or tries to associate automatically
* after deauth/disassoc).
*/
for (i = 0; i < 32; i++)
for (i = 0; i < SSID_MAX_LEN; i++)
ssid[i] = rand() & 0xFF;
if (wpa_driver_wext_set_ssid(drv, ssid, 32) < 0) {
if (wpa_driver_wext_set_ssid(drv, ssid, SSID_MAX_LEN) < 0) {
wpa_printf(MSG_DEBUG, "WEXT: Failed to set bogus "
"SSID to disconnect");
}

@ -9,6 +9,7 @@
#ifndef P2P_H
#define P2P_H
#include "common/ieee802_11_defs.h"
#include "wps/wps_defs.h"
/* P2P ASP Setup Capability */
@ -95,7 +96,7 @@ struct p2p_go_neg_results {
/**
* ssid - SSID of the group
*/
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
/**
* ssid_len - Length of SSID in octets
@ -495,7 +496,7 @@ struct p2p_config {
* This data will be added to the end of the SSID after the
* DIRECT-<random two octets> prefix.
*/
u8 ssid_postfix[32 - 9];
u8 ssid_postfix[SSID_MAX_LEN - 9];
/**
* ssid_postfix_len - Length of the ssid_postfix data
@ -1607,7 +1608,7 @@ struct p2p_group_config {
/**
* ssid - Group SSID
*/
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
/**
* ssid_len - Length of SSID
@ -2214,7 +2215,7 @@ struct p2p_nfc_params {
size_t oob_dev_pw_len;
int go_freq;
u8 go_dev_addr[ETH_ALEN];
u8 go_ssid[32];
u8 go_ssid[SSID_MAX_LEN];
size_t go_ssid_len;
};

@ -71,7 +71,7 @@ struct p2p_device {
char country[3];
struct p2p_channels channels;
int oper_freq;
u8 oper_ssid[32];
u8 oper_ssid[SSID_MAX_LEN];
size_t oper_ssid_len;
/**
@ -322,7 +322,7 @@ struct p2p_data {
/**
* ssid - Selected SSID for GO Negotiation (if local end will be GO)
*/
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
/**
* ssid_len - ssid length in octets
@ -403,7 +403,7 @@ struct p2p_data {
enum p2p_invite_role inv_role;
u8 inv_bssid[ETH_ALEN];
int inv_bssid_set;
u8 inv_ssid[32];
u8 inv_ssid[SSID_MAX_LEN];
size_t inv_ssid_len;
u8 inv_sa[ETH_ALEN];
u8 inv_group_bssid[ETH_ALEN];

@ -387,7 +387,7 @@ fail:
} else
p2p->inv_group_bssid_ptr = NULL;
if (msg.group_id) {
if (msg.group_id_len - ETH_ALEN <= 32) {
if (msg.group_id_len - ETH_ALEN <= SSID_MAX_LEN) {
os_memcpy(p2p->inv_ssid, msg.group_id + ETH_ALEN,
msg.group_id_len - ETH_ALEN);
p2p->inv_ssid_len = msg.group_id_len - ETH_ALEN;

@ -204,7 +204,7 @@ static int p2p_parse_attribute(u8 id, const u8 *data, u16 len,
MAC2STR(msg->group_bssid));
break;
case P2P_ATTR_GROUP_ID:
if (len < ETH_ALEN || len > ETH_ALEN + 32) {
if (len < ETH_ALEN || len > ETH_ALEN + SSID_MAX_LEN) {
wpa_printf(MSG_DEBUG, "P2P: Invalid P2P Group ID "
"attribute length %d", len);
return -1;

@ -44,7 +44,7 @@ static void p2ps_add_new_group_info(struct p2p_data *p2p, struct wpabuf *buf)
{
int found;
u8 intended_addr[ETH_ALEN];
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
size_t ssid_len;
int group_iface;
@ -84,7 +84,7 @@ static void p2ps_add_pd_req_attrs(struct p2p_data *p2p, struct p2p_device *dev,
struct p2ps_provision *prov = p2p->p2ps_prov;
u8 feat_cap_mask[] = { 1, 0 };
int shared_group = 0;
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
size_t ssid_len;
u8 go_dev_addr[ETH_ALEN];
@ -293,7 +293,7 @@ static struct wpabuf * p2p_build_prov_disc_resp(struct p2p_data *p2p,
if (persist_ssid && p2p->cfg->get_persistent_group &&
(status == P2P_SC_SUCCESS ||
status == P2P_SC_SUCCESS_DEFERRED)) {
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
size_t ssid_len;
u8 go_dev_addr[ETH_ALEN];

@ -8,6 +8,7 @@
#include "includes.h"
#include "common/ieee802_11_defs.h"
#include "common.h"
@ -609,7 +610,7 @@ size_t printf_decode(u8 *buf, size_t maxlen, const char *str)
*/
const char * wpa_ssid_txt(const u8 *ssid, size_t ssid_len)
{
static char ssid_txt[32 * 4 + 1];
static char ssid_txt[SSID_MAX_LEN * 4 + 1];
if (ssid == NULL) {
ssid_txt[0] = '\0';

@ -9,6 +9,7 @@
#ifndef WPS_H
#define WPS_H
#include "common/ieee802_11_defs.h"
#include "wps_defs.h"
/**
@ -44,7 +45,7 @@ struct wps_parse_attr;
* @cred_attr_len: Length of cred_attr in octets
*/
struct wps_credential {
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
size_t ssid_len;
u16 auth_type;
u16 encr_type;
@ -623,7 +624,7 @@ struct wps_context {
* Credentials. In addition, AP uses it when acting as an Enrollee to
* notify Registrar of the current configuration.
*/
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
/**
* ssid_len - Length of ssid in octets

@ -652,7 +652,7 @@ void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s,
MACSTR, MAC2STR(res->bssid));
return;
}
if (ssid[1] > 32) {
if (ssid[1] > SSID_MAX_LEN) {
wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Too long SSID IE included for "
MACSTR, MAC2STR(res->bssid));
return;
@ -679,7 +679,7 @@ void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s,
* (to save memory) */
mesh = wpa_scan_get_ie(res, WLAN_EID_MESH_ID);
if (mesh && mesh[1] <= 32)
if (mesh && mesh[1] <= SSID_MAX_LEN)
ssid = mesh;
bss = wpa_bss_get(wpa_s, res->bssid, ssid + 2, ssid[1]);

@ -69,7 +69,7 @@ struct wpa_bss {
/** HESSID */
u8 hessid[ETH_ALEN];
/** SSID */
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
/** Length of SSID */
size_t ssid_len;
/** Frequency of the channel in MHz (e.g., 2412 = channel 1) */

@ -153,7 +153,8 @@ static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
}
ssid = ns;
if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
if ((end - pos) & 0x01 ||
end - pos > 2 * SSID_MAX_LEN ||
hexstr2bin(pos, ssid[ssid_count].ssid,
(end - pos) / 2) < 0) {
os_free(ssid);
@ -7706,7 +7707,7 @@ static int wpas_ctrl_iface_send_neigbor_rep(struct wpa_supplicant *wpa_s,
if (os_strncmp(cmd, " ssid=", 6) == 0) {
ssid.ssid_len = os_strlen(cmd + 6);
if (ssid.ssid_len > 32)
if (ssid.ssid_len > SSID_MAX_LEN)
return -1;
ssid.ssid = (u8 *) (cmd + 6);
ssid_p = &ssid;

@ -46,7 +46,7 @@ struct osu_icon {
struct osu_provider {
u8 bssid[ETH_ALEN];
u8 osu_ssid[32];
u8 osu_ssid[SSID_MAX_LEN];
u8 osu_ssid_len;
char server_uri[256];
u32 osu_methods; /* bit 0 = OMA-DM, bit 1 = SOAP-XML SPP */
@ -822,7 +822,7 @@ void hs20_osu_icon_fetch(struct wpa_supplicant *wpa_s)
continue;
}
osu_ssid_len = *pos++;
if (osu_ssid_len > 32) {
if (osu_ssid_len > SSID_MAX_LEN) {
wpa_printf(MSG_DEBUG, "HS 2.0: Invalid OSU SSID "
"Length %u", osu_ssid_len);
continue;

@ -967,12 +967,12 @@ static int wpa_cli_cmd_wps_reg(struct wpa_ctrl *ctrl, int argc, char *argv[])
res = os_snprintf(cmd, sizeof(cmd), "WPS_REG %s %s",
argv[0], argv[1]);
else if (argc == 5 || argc == 6) {
char ssid_hex[2 * 32 + 1];
char ssid_hex[2 * SSID_MAX_LEN + 1];
char key_hex[2 * 64 + 1];
int i;
ssid_hex[0] = '\0';
for (i = 0; i < 32; i++) {
for (i = 0; i < SSID_MAX_LEN; i++) {
if (argv[2][i] == '\0')
break;
os_snprintf(&ssid_hex[i * 2], 3, "%02x", argv[2][i]);
@ -1096,12 +1096,12 @@ static int wpa_cli_cmd_wps_er_config(struct wpa_ctrl *ctrl, int argc,
int res;
if (argc == 5 || argc == 6) {
char ssid_hex[2 * 32 + 1];
char ssid_hex[2 * SSID_MAX_LEN + 1];
char key_hex[2 * 64 + 1];
int i;
ssid_hex[0] = '\0';
for (i = 0; i < 32; i++) {
for (i = 0; i < SSID_MAX_LEN; i++) {
if (argv[2][i] == '\0')
break;
os_snprintf(&ssid_hex[i * 2], 3, "%02x", argv[2][i]);

@ -199,7 +199,7 @@ static void wpa_priv_cmd_associate(struct wpa_priv_interface *iface,
if (bssid[0] | bssid[1] | bssid[2] | bssid[3] | bssid[4] | bssid[5])
params.bssid = bssid;
params.ssid = assoc->ssid;
if (assoc->ssid_len > 32)
if (assoc->ssid_len > SSID_MAX_LEN)
return;
params.ssid_len = assoc->ssid_len;
params.freq.mode = assoc->hwmode;
@ -244,7 +244,7 @@ fail:
static void wpa_priv_cmd_get_ssid(struct wpa_priv_interface *iface,
struct sockaddr_un *from)
{
u8 ssid[sizeof(int) + 32];
u8 ssid[sizeof(int) + SSID_MAX_LEN];
int res;
if (iface->drv_priv == NULL)
@ -254,7 +254,7 @@ static void wpa_priv_cmd_get_ssid(struct wpa_priv_interface *iface,
goto fail;
res = iface->driver->get_ssid(iface->drv_priv, &ssid[sizeof(int)]);
if (res < 0 || res > 32)
if (res < 0 || res > SSID_MAX_LEN)
goto fail;
os_memcpy(ssid, &res, sizeof(int));

@ -369,7 +369,7 @@ struct wps_ap_info {
};
struct wpa_ssid_value {
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
size_t ssid_len;
};
@ -662,7 +662,7 @@ struct wpa_supplicant {
#ifdef CONFIG_SME
struct {
u8 ssid[32];
u8 ssid[SSID_MAX_LEN];
size_t ssid_len;
int freq;
u8 assoc_req_ie[200];
@ -768,7 +768,7 @@ struct wpa_supplicant {
u8 pending_join_iface_addr[ETH_ALEN];
u8 pending_join_dev_addr[ETH_ALEN];
int pending_join_wps_method;
u8 p2p_join_ssid[32];
u8 p2p_join_ssid[SSID_MAX_LEN];
size_t p2p_join_ssid_len;
int p2p_join_scan_count;
int auto_pd_scan_retry;

@ -1910,7 +1910,7 @@ static int wpas_wps_network_to_cred(struct wpa_ssid *ssid,
struct wps_credential *cred)
{
os_memset(cred, 0, sizeof(*cred));
if (ssid->ssid_len > 32)
if (ssid->ssid_len > SSID_MAX_LEN)
return -1;
os_memcpy(cred->ssid, ssid->ssid, ssid->ssid_len);
cred->ssid_len = ssid->ssid_len;

Loading…
Cancel
Save