Add dup_binstr() to help common binary string tasks

There are quite a few places in the current implementation where a nul
terminated string is generated from binary data. Add a helper function
to simplify the code a bit.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2013-04-27 23:44:59 +03:00
parent 8b44ad7e16
commit 5e24dc8a4b
18 changed files with 51 additions and 116 deletions

View file

@ -399,15 +399,13 @@ static void ieee802_1x_learn_identity(struct hostapd_data *hapd,
/* Save station identity for future RADIUS packets */
os_free(sm->identity);
sm->identity = os_malloc(identity_len + 1);
sm->identity = (u8 *) dup_binstr(identity, identity_len);
if (sm->identity == NULL) {
sm->identity_len = 0;
return;
}
os_memcpy(sm->identity, identity, identity_len);
sm->identity_len = identity_len;
sm->identity[identity_len] = '\0';
hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
HOSTAPD_LEVEL_DEBUG, "STA identity '%s'", sm->identity);
sm->dot1xAuthEapolRespIdFramesRx++;
@ -1272,13 +1270,10 @@ static void ieee802_1x_update_sta_identity(struct hostapd_data *hapd,
NULL) < 0)
return;
identity = os_malloc(len + 1);
identity = (u8 *) dup_binstr(buf, len);
if (identity == NULL)
return;
os_memcpy(identity, buf, len);
identity[len] = '\0';
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
HOSTAPD_LEVEL_DEBUG, "old identity '%s' updated with "
"User-Name from Access-Accept '%s'",