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>
This commit is contained in:
parent
dbdda355d0
commit
a1f11e34c4
73 changed files with 201 additions and 376 deletions
|
@ -175,7 +175,7 @@ int eap_sim_verify_mac(const u8 *k_aut, const struct wpabuf *req,
|
|||
mac > wpabuf_head_u8(req) + wpabuf_len(req) - EAP_SIM_MAC_LEN)
|
||||
return -1;
|
||||
|
||||
tmp = os_malloc(wpabuf_len(req));
|
||||
tmp = os_memdup(wpabuf_head(req), wpabuf_len(req));
|
||||
if (tmp == NULL)
|
||||
return -1;
|
||||
|
||||
|
@ -185,7 +185,6 @@ int eap_sim_verify_mac(const u8 *k_aut, const struct wpabuf *req,
|
|||
len[1] = extra_len;
|
||||
|
||||
/* HMAC-SHA1-128 */
|
||||
os_memcpy(tmp, wpabuf_head(req), wpabuf_len(req));
|
||||
os_memset(tmp + (mac - wpabuf_head_u8(req)), 0, EAP_SIM_MAC_LEN);
|
||||
wpa_hexdump(MSG_MSGDUMP, "EAP-SIM: Verify MAC - msg",
|
||||
tmp, wpabuf_len(req));
|
||||
|
@ -370,7 +369,7 @@ int eap_sim_verify_mac_sha256(const u8 *k_aut, const struct wpabuf *req,
|
|||
mac > wpabuf_head_u8(req) + wpabuf_len(req) - EAP_SIM_MAC_LEN)
|
||||
return -1;
|
||||
|
||||
tmp = os_malloc(wpabuf_len(req));
|
||||
tmp = os_memdup(wpabuf_head(req), wpabuf_len(req));
|
||||
if (tmp == NULL)
|
||||
return -1;
|
||||
|
||||
|
@ -380,7 +379,6 @@ int eap_sim_verify_mac_sha256(const u8 *k_aut, const struct wpabuf *req,
|
|||
len[1] = extra_len;
|
||||
|
||||
/* HMAC-SHA-256-128 */
|
||||
os_memcpy(tmp, wpabuf_head(req), wpabuf_len(req));
|
||||
os_memset(tmp + (mac - wpabuf_head_u8(req)), 0, EAP_SIM_MAC_LEN);
|
||||
wpa_hexdump(MSG_MSGDUMP, "EAP-AKA': Verify MAC - msg",
|
||||
tmp, wpabuf_len(req));
|
||||
|
@ -943,10 +941,9 @@ u8 * eap_sim_parse_encr(const u8 *k_encr, const u8 *encr_data,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
decrypted = os_malloc(encr_data_len);
|
||||
decrypted = os_memdup(encr_data, encr_data_len);
|
||||
if (decrypted == NULL)
|
||||
return NULL;
|
||||
os_memcpy(decrypted, encr_data, encr_data_len);
|
||||
|
||||
if (aes_128_cbc_decrypt(k_encr, iv, decrypted, encr_data_len)) {
|
||||
os_free(decrypted);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue