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:
parent
8b44ad7e16
commit
5e24dc8a4b
18 changed files with 51 additions and 116 deletions
|
@ -1480,7 +1480,6 @@ int eap_sim_db_resynchronize(struct eap_sim_db_data *data,
|
|||
*/
|
||||
char * sim_get_username(const u8 *identity, size_t identity_len)
|
||||
{
|
||||
char *username;
|
||||
size_t pos;
|
||||
|
||||
if (identity == NULL)
|
||||
|
@ -1491,11 +1490,5 @@ char * sim_get_username(const u8 *identity, size_t identity_len)
|
|||
break;
|
||||
}
|
||||
|
||||
username = os_malloc(pos + 1);
|
||||
if (username == NULL)
|
||||
return NULL;
|
||||
os_memcpy(username, identity, pos);
|
||||
username[pos] = '\0';
|
||||
|
||||
return username;
|
||||
return dup_binstr(identity, pos);
|
||||
}
|
||||
|
|
|
@ -851,12 +851,10 @@ enum tncs_process_res tncs_process_if_tnccs(struct tncs_data *tncs,
|
|||
unsigned char *decoded;
|
||||
size_t decoded_len;
|
||||
|
||||
buf = os_malloc(len + 1);
|
||||
buf = dup_binstr(msg, len);
|
||||
if (buf == NULL)
|
||||
return TNCCS_PROCESS_ERROR;
|
||||
|
||||
os_memcpy(buf, msg, len);
|
||||
buf[len] = '\0';
|
||||
start = os_strstr(buf, "<TNCCS-Batch ");
|
||||
end = os_strstr(buf, "</TNCCS-Batch>");
|
||||
if (start == NULL || end == NULL || start > end) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue