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
|
@ -96,12 +96,11 @@ static void * eap_gpsk_init(struct eap_sm *sm)
|
|||
|
||||
identity = eap_get_config_identity(sm, &identity_len);
|
||||
if (identity) {
|
||||
data->id_peer = os_malloc(identity_len);
|
||||
data->id_peer = os_memdup(identity, identity_len);
|
||||
if (data->id_peer == NULL) {
|
||||
eap_gpsk_deinit(sm, data);
|
||||
return NULL;
|
||||
}
|
||||
os_memcpy(data->id_peer, identity, identity_len);
|
||||
data->id_peer_len = identity_len;
|
||||
}
|
||||
|
||||
|
@ -117,12 +116,11 @@ static void * eap_gpsk_init(struct eap_sm *sm)
|
|||
}
|
||||
}
|
||||
|
||||
data->psk = os_malloc(password_len);
|
||||
data->psk = os_memdup(password, password_len);
|
||||
if (data->psk == NULL) {
|
||||
eap_gpsk_deinit(sm, data);
|
||||
return NULL;
|
||||
}
|
||||
os_memcpy(data->psk, password, password_len);
|
||||
data->psk_len = password_len;
|
||||
|
||||
return data;
|
||||
|
@ -158,12 +156,11 @@ static const u8 * eap_gpsk_process_id_server(struct eap_gpsk_data *data,
|
|||
return NULL;
|
||||
}
|
||||
os_free(data->id_server);
|
||||
data->id_server = os_malloc(alen);
|
||||
data->id_server = os_memdup(pos, alen);
|
||||
if (data->id_server == NULL) {
|
||||
wpa_printf(MSG_DEBUG, "EAP-GPSK: No memory for ID_Server");
|
||||
return NULL;
|
||||
}
|
||||
os_memcpy(data->id_server, pos, alen);
|
||||
data->id_server_len = alen;
|
||||
wpa_hexdump_ascii(MSG_DEBUG, "EAP-GPSK: ID_Server",
|
||||
data->id_server, data->id_server_len);
|
||||
|
@ -722,10 +719,9 @@ static u8 * eap_gpsk_getKey(struct eap_sm *sm, void *priv, size_t *len)
|
|||
if (data->state != SUCCESS)
|
||||
return NULL;
|
||||
|
||||
key = os_malloc(EAP_MSK_LEN);
|
||||
key = os_memdup(data->msk, EAP_MSK_LEN);
|
||||
if (key == NULL)
|
||||
return NULL;
|
||||
os_memcpy(key, data->msk, EAP_MSK_LEN);
|
||||
*len = EAP_MSK_LEN;
|
||||
|
||||
return key;
|
||||
|
@ -740,10 +736,9 @@ static u8 * eap_gpsk_get_emsk(struct eap_sm *sm, void *priv, size_t *len)
|
|||
if (data->state != SUCCESS)
|
||||
return NULL;
|
||||
|
||||
key = os_malloc(EAP_EMSK_LEN);
|
||||
key = os_memdup(data->emsk, EAP_EMSK_LEN);
|
||||
if (key == NULL)
|
||||
return NULL;
|
||||
os_memcpy(key, data->emsk, EAP_EMSK_LEN);
|
||||
*len = EAP_EMSK_LEN;
|
||||
|
||||
return key;
|
||||
|
@ -758,10 +753,9 @@ static u8 * eap_gpsk_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
|
|||
if (data->state != SUCCESS)
|
||||
return NULL;
|
||||
|
||||
sid = os_malloc(data->id_len);
|
||||
sid = os_memdup(data->session_id, data->id_len);
|
||||
if (sid == NULL)
|
||||
return NULL;
|
||||
os_memcpy(sid, data->session_id, data->id_len);
|
||||
*len = data->id_len;
|
||||
|
||||
return sid;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue