aboutsummaryrefslogtreecommitdiffstats
path: root/wlantest
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2017-03-07 09:17:23 (GMT)
committerJouni Malinen <j@w1.fi>2017-03-07 11:19:10 (GMT)
commita1f11e34c4d6a10bdfef58cdba0b19e1335e087b (patch)
treef3ff7d078578a4b4a7ccf20058e65f1ddb96c622 /wlantest
parentdbdda355d0add3f7d96e3279321d3a63abfc4b32 (diff)
downloadhostap-a1f11e34c4d6a10bdfef58cdba0b19e1335e087b.zip
hostap-a1f11e34c4d6a10bdfef58cdba0b19e1335e087b.tar.gz
hostap-a1f11e34c4d6a10bdfef58cdba0b19e1335e087b.tar.bz2
Use os_memdup()
This leads to cleaner code overall, and also reduces the size of the hostapd and wpa_supplicant binaries (in hwsim test build on x86_64) by about 2.5 and 3.5KiB respectively. The mechanical conversions all over the code were done with the following spatch: @@ expression SIZE, SRC; expression a; @@ -a = os_malloc(SIZE); +a = os_memdup(SRC, SIZE); <... if (!a) {...} ...> -os_memcpy(a, SRC, SIZE); Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'wlantest')
-rw-r--r--wlantest/rx_eapol.c6
-rw-r--r--wlantest/tkip.c3
2 files changed, 3 insertions, 6 deletions
diff --git a/wlantest/rx_eapol.c b/wlantest/rx_eapol.c
index e04e5aa..aa0566d 100644
--- a/wlantest/rx_eapol.c
+++ b/wlantest/rx_eapol.c
@@ -41,10 +41,9 @@ static int check_mic(const u8 *kck, size_t kck_len, int akmp, int ver,
u8 rx_mic[WPA_EAPOL_KEY_MIC_MAX_LEN];
size_t mic_len = wpa_mic_len(akmp);
- buf = os_malloc(len);
+ buf = os_memdup(data, len);
if (buf == NULL)
return -1;
- os_memcpy(buf, data, len);
hdr = (struct ieee802_1x_hdr *) buf;
key = (struct wpa_eapol_key *) (hdr + 1);
@@ -355,13 +354,12 @@ static u8 * decrypt_eapol_key_data_rc4(struct wlantest *wt, const u8 *kek,
{
u8 ek[32], *buf;
- buf = os_malloc(keydatalen);
+ buf = os_memdup(keydata, keydatalen);
if (buf == NULL)
return NULL;
os_memcpy(ek, hdr->key_iv, 16);
os_memcpy(ek + 16, kek, 16);
- os_memcpy(buf, keydata, keydatalen);
if (rc4_skip(ek, 32, 256, buf, keydatalen)) {
add_note(wt, MSG_INFO, "RC4 failed");
os_free(buf);
diff --git a/wlantest/tkip.c b/wlantest/tkip.c
index 63366d5..d616d43 100644
--- a/wlantest/tkip.c
+++ b/wlantest/tkip.c
@@ -318,10 +318,9 @@ u8 * tkip_decrypt(const u8 *tk, const struct ieee80211_hdr *hdr,
wpa_hexdump(MSG_EXCESSIVE, "TKIP RC4KEY", rc4key, sizeof(rc4key));
plain_len = data_len - 8;
- plain = os_malloc(plain_len);
+ plain = os_memdup(data + 8, plain_len);
if (plain == NULL)
return NULL;
- os_memcpy(plain, data + 8, plain_len);
wep_crypt(rc4key, plain, plain_len);
icv = crc32(plain, plain_len - 4);