]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Convert remaining SSID routines from char* to u8*
authorJouni Malinen <j@w1.fi>
Tue, 7 Aug 2012 13:07:25 +0000 (16:07 +0300)
committerJouni Malinen <j@w1.fi>
Tue, 7 Aug 2012 13:07:25 +0000 (16:07 +0300)
This makes it more explicit that the SSID is not a null terminated
C string.

Signed-hostap: Jouni Malinen <j@w1.fi>

15 files changed:
hostapd/config_file.c
hostapd/ctrl_iface.c
hostapd/main.c
src/ap/accounting.c
src/ap/ap_config.h
src/ap/beacon.c
src/ap/hostapd.c
src/ap/ieee802_11_auth.c
src/ap/ieee802_1x.c
src/crypto/sha1-pbkdf2.c
src/crypto/sha1.h
wpa_supplicant/ap.c
wpa_supplicant/config.c
wpa_supplicant/wpa_passphrase.c
wpa_supplicant/wpa_supplicant.c

index 42c1ccbcfdd8e8e9fcf27c263c28bd74da920b3f..1f898dbb259e031b246c9c0b83b9a9c2f00f11b6 100644 (file)
@@ -1470,7 +1470,6 @@ static int hostapd_config_fill(struct hostapd_config *conf,
                        } else {
                                os_memcpy(bss->ssid.ssid, pos,
                                          bss->ssid.ssid_len);
-                               bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
                                bss->ssid.ssid_set = 1;
                        }
                } else if (os_strcmp(buf, "macaddr_acl") == 0) {
index 7587e0328ea3dfa72865ef9461be19a77c13896d..77146e3e5ab825b6334ff44473080df8424250b5 100644 (file)
@@ -523,7 +523,8 @@ static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
        ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n"
                          "ssid=%s\n",
                          MAC2STR(hapd->own_addr),
-                         hapd->conf->ssid.ssid);
+                         wpa_ssid_txt(hapd->conf->ssid.ssid,
+                                      hapd->conf->ssid.ssid_len));
        if (ret < 0 || ret >= end - pos)
                return pos - buf;
        pos += ret;
index d8c27765c5fb1343e19d6928b68407c6567fa32c..3826ccf8303f3c5fa778e16ca455b82e3d9b99ef 100644 (file)
@@ -248,7 +248,7 @@ static int hostapd_driver_init(struct hostapd_iface *iface)
        }
        params.bssid = b;
        params.ifname = hapd->conf->iface;
-       params.ssid = (const u8 *) hapd->conf->ssid.ssid;
+       params.ssid = hapd->conf->ssid.ssid;
        params.ssid_len = hapd->conf->ssid.ssid_len;
        params.test_socket = hapd->conf->test_socket;
        params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
index 0b838a4cb95152bc943467fd9c7a40a55d40c559..e027d53864ad0b94ad07d85eb1d77e4747c34737 100644 (file)
@@ -136,7 +136,9 @@ static struct radius_msg * accounting_msg(struct hostapd_data *hapd,
        }
 
        os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":%s",
-                   MAC2STR(hapd->own_addr), hapd->conf->ssid.ssid);
+                   MAC2STR(hapd->own_addr),
+                   wpa_ssid_txt(hapd->conf->ssid.ssid,
+                                hapd->conf->ssid.ssid_len));
        if (!hostapd_config_get_radius_attr(hapd->conf->radius_acct_req_attr,
                                            RADIUS_ATTR_CALLED_STATION_ID) &&
            !radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
index 98c6f95390fb3657026c7db7836e901ac8e54644..bfb2d8af2578f1f8836fded7573d3e46021f7ad6 100644 (file)
@@ -48,7 +48,7 @@ typedef enum hostap_security_policy {
 } secpolicy;
 
 struct hostapd_ssid {
-       char ssid[HOSTAPD_MAX_SSID_LEN + 1];
+       u8 ssid[HOSTAPD_MAX_SSID_LEN];
        size_t ssid_len;
        int ssid_set;
 
index ef97c6e7da659302cf2e64702b71e4552a9a8a4c..ca3f054bcf1dbad767bc030cd43e242ad74bdda8 100644 (file)
@@ -653,7 +653,7 @@ void ieee802_11_set_beacon(struct hostapd_data *hapd)
        params.dtim_period = hapd->conf->dtim_period;
        params.beacon_int = hapd->iconf->beacon_int;
        params.basic_rates = hapd->iconf->basic_rates;
-       params.ssid = (u8 *) hapd->conf->ssid.ssid;
+       params.ssid = hapd->conf->ssid.ssid;
        params.ssid_len = hapd->conf->ssid.ssid_len;
        params.pairwise_ciphers = hapd->conf->rsn_pairwise ?
                hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
index 22c5e654a44cde7794b776d9cbb03ca04d78ba09..ba8d83243b8adee88dc76e61d21030b94999fdeb 100644 (file)
@@ -98,7 +98,7 @@ static void hostapd_reload_bss(struct hostapd_data *hapd)
        hostapd_update_wps(hapd);
 
        if (hapd->conf->ssid.ssid_set &&
-           hostapd_set_ssid(hapd, (u8 *) hapd->conf->ssid.ssid,
+           hostapd_set_ssid(hapd, hapd->conf->ssid.ssid,
                             hapd->conf->ssid.ssid_len)) {
                wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
                /* try to continue */
@@ -679,14 +679,14 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
                set_ssid = 0;
                conf->ssid.ssid_len = ssid_len;
                os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
-               conf->ssid.ssid[conf->ssid.ssid_len] = '\0';
        }
 
        if (!hostapd_drv_none(hapd)) {
                wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
-                          " and ssid '%s'",
+                          " and ssid \"%s\"",
                           hapd->conf->iface, MAC2STR(hapd->own_addr),
-                          hapd->conf->ssid.ssid);
+                          wpa_ssid_txt(hapd->conf->ssid.ssid,
+                                       hapd->conf->ssid.ssid_len));
        }
 
        if (hostapd_setup_wpa_psk(conf)) {
@@ -696,7 +696,7 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
 
        /* Set SSID for the kernel driver (to be used in beacon and probe
         * response frames) */
-       if (set_ssid && hostapd_set_ssid(hapd, (u8 *) conf->ssid.ssid,
+       if (set_ssid && hostapd_set_ssid(hapd, conf->ssid.ssid,
                                         conf->ssid.ssid_len)) {
                wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
                return -1;
index 0c4c5f3274aec1bf431b52984f059b861c24f73f..e30d85abaa52874bd0f0802eba839996ee2ae812 100644 (file)
@@ -165,7 +165,9 @@ static int hostapd_radius_acl_query(struct hostapd_data *hapd, const u8 *addr,
        }
 
        os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":%s",
-                   MAC2STR(hapd->own_addr), hapd->conf->ssid.ssid);
+                   MAC2STR(hapd->own_addr),
+                   wpa_ssid_txt(hapd->conf->ssid.ssid,
+                                hapd->conf->ssid.ssid_len));
        if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
                                 (u8 *) buf, os_strlen(buf))) {
                wpa_printf(MSG_DEBUG, "Could not add Called-Station-Id");
index dd0df1d38e480d57f122b76eb9d173a8221a27d1..25b5065cb416902e64bce2a78179b4861808f542 100644 (file)
@@ -481,7 +481,9 @@ static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
        }
 
        os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":%s",
-                   MAC2STR(hapd->own_addr), hapd->conf->ssid.ssid);
+                   MAC2STR(hapd->own_addr),
+                   wpa_ssid_txt(hapd->conf->ssid.ssid,
+                                hapd->conf->ssid.ssid_len));
        buf[sizeof(buf) - 1] = '\0';
        if (!hostapd_config_get_radius_attr(hapd->conf->radius_auth_req_attr,
                                            RADIUS_ATTR_CALLED_STATION_ID) &&
index 450c2a0364b8685900a4f62dbeb7c08affb93332..8effe2fe063a865c39bb144ac79768b0d028a7db 100644 (file)
@@ -11,7 +11,7 @@
 #include "common.h"
 #include "sha1.h"
 
-static int pbkdf2_sha1_f(const char *passphrase, const char *ssid,
+static int pbkdf2_sha1_f(const char *passphrase, const u8 *ssid,
                         size_t ssid_len, int iterations, unsigned int count,
                         u8 *digest)
 {
@@ -22,7 +22,7 @@ static int pbkdf2_sha1_f(const char *passphrase, const char *ssid,
        size_t len[2];
        size_t passphrase_len = os_strlen(passphrase);
 
-       addr[0] = (u8 *) ssid;
+       addr[0] = ssid;
        len[0] = ssid_len;
        addr[1] = count_buf;
        len[1] = 4;
@@ -69,7 +69,7 @@ static int pbkdf2_sha1_f(const char *passphrase, const char *ssid,
  * iterations is set to 4096 and buflen to 32. This function is described in
  * IEEE Std 802.11-2004, Clause H.4. The main construction is from PKCS#5 v2.0.
  */
-int pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len,
+int pbkdf2_sha1(const char *passphrase, const u8 *ssid, size_t ssid_len,
                int iterations, u8 *buf, size_t buflen)
 {
        unsigned int count = 0;
index 08e5a59dedcf243f9cd7c4450fd77628c8b9ccbd..933cd81b95b3a81d8557a2afa7f33561d76d62c0 100644 (file)
@@ -22,6 +22,6 @@ int sha1_t_prf(const u8 *key, size_t key_len, const char *label,
 int __must_check tls_prf_sha1_md5(const u8 *secret, size_t secret_len,
                                  const char *label, const u8 *seed,
                                  size_t seed_len, u8 *out, size_t outlen);
-int pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len,
+int pbkdf2_sha1(const char *passphrase, const u8 *ssid, size_t ssid_len,
                int iterations, u8 *buf, size_t buflen);
 #endif /* SHA1_H */
index f9e0045703a1f841020ae12fc805b69634acdb2b..80c1783cce21a3c90093ef4d0c5a6c933d7e017f 100644 (file)
@@ -150,7 +150,6 @@ static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
                return -1;
        }
        os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
-       bss->ssid.ssid[ssid->ssid_len] = '\0';
        bss->ssid.ssid_len = ssid->ssid_len;
        bss->ssid.ssid_set = 1;
 
index 94052c5fab62868635fa10dc188f6f3fd32a58eb..c09f3104ea02fa6ba2b41bdd335e4ec66af03e19 100644 (file)
@@ -2308,8 +2308,7 @@ char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
 void wpa_config_update_psk(struct wpa_ssid *ssid)
 {
 #ifndef CONFIG_NO_PBKDF2
-       pbkdf2_sha1(ssid->passphrase,
-                   (char *) ssid->ssid, ssid->ssid_len, 4096,
+       pbkdf2_sha1(ssid->passphrase, ssid->ssid, ssid->ssid_len, 4096,
                    ssid->psk, PMK_LEN);
        wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
                        ssid->psk, PMK_LEN);
index a9ec23618672d6008df8d156f8a66ad4885c954b..9b568f0f7c672c84506b63ff0ad95af8adc15c21 100644 (file)
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
                return 1;
        }
 
-       pbkdf2_sha1(passphrase, ssid, os_strlen(ssid), 4096, psk, 32);
+       pbkdf2_sha1(passphrase, (u8 *) ssid, os_strlen(ssid), 4096, psk, 32);
 
        printf("network={\n");
        printf("\tssid=\"%s\"\n", ssid);
index 61fbec99cb804cd3424eb0a35f0fa3a64bea47c0..9a4257050556d7a374ac95e3184c6c5549c67c34 100644 (file)
@@ -1097,8 +1097,8 @@ int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
                if (bss && ssid->bssid_set && ssid->ssid_len == 0 &&
                    ssid->passphrase) {
                        u8 psk[PMK_LEN];
-                       pbkdf2_sha1(ssid->passphrase, (char *) bss->ssid,
-                                   bss->ssid_len, 4096, psk, PMK_LEN);
+                       pbkdf2_sha1(ssid->passphrase, bss->ssid, bss->ssid_len,
+                                   4096, psk, PMK_LEN);
                        wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
                                        psk, PMK_LEN);
                        wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN);
@@ -1131,8 +1131,8 @@ int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
 #ifndef CONFIG_NO_PBKDF2
                        if (wpabuf_len(pw) >= 8 && wpabuf_len(pw) < 64 && bss)
                        {
-                               pbkdf2_sha1(pw_str, (char *) bss->ssid,
-                                           bss->ssid_len, 4096, psk, PMK_LEN);
+                               pbkdf2_sha1(pw_str, bss->ssid, bss->ssid_len,
+                                           4096, psk, PMK_LEN);
                                os_memset(pw_str, 0, sizeof(pw_str));
                                wpa_hexdump_key(MSG_MSGDUMP, "PSK (from "
                                                "external passphrase)",