mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2025-02-21 11:33:04 -05:00
Make wpa_config_parse_string() a shared function
This will be used in future hostapd configuration parser changes. Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
986de33d5c
commit
b87d70c88a
@ -505,3 +505,64 @@ void * __hide_aliasing_typecast(void *foo)
|
|||||||
{
|
{
|
||||||
return foo;
|
return foo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char * wpa_config_parse_string(const char *value, size_t *len)
|
||||||
|
{
|
||||||
|
if (*value == '"') {
|
||||||
|
const char *pos;
|
||||||
|
char *str;
|
||||||
|
value++;
|
||||||
|
pos = os_strrchr(value, '"');
|
||||||
|
if (pos == NULL || pos[1] != '\0')
|
||||||
|
return NULL;
|
||||||
|
*len = pos - value;
|
||||||
|
str = os_malloc(*len + 1);
|
||||||
|
if (str == NULL)
|
||||||
|
return NULL;
|
||||||
|
os_memcpy(str, value, *len);
|
||||||
|
str[*len] = '\0';
|
||||||
|
return str;
|
||||||
|
} else if (*value == 'P' && value[1] == '"') {
|
||||||
|
const char *pos;
|
||||||
|
char *tstr, *str;
|
||||||
|
size_t tlen;
|
||||||
|
value += 2;
|
||||||
|
pos = os_strrchr(value, '"');
|
||||||
|
if (pos == NULL || pos[1] != '\0')
|
||||||
|
return NULL;
|
||||||
|
tlen = pos - value;
|
||||||
|
tstr = os_malloc(tlen + 1);
|
||||||
|
if (tstr == NULL)
|
||||||
|
return NULL;
|
||||||
|
os_memcpy(tstr, value, tlen);
|
||||||
|
tstr[tlen] = '\0';
|
||||||
|
|
||||||
|
str = os_malloc(tlen + 1);
|
||||||
|
if (str == NULL) {
|
||||||
|
os_free(tstr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*len = printf_decode((u8 *) str, tlen + 1, tstr);
|
||||||
|
os_free(tstr);
|
||||||
|
|
||||||
|
return str;
|
||||||
|
} else {
|
||||||
|
u8 *str;
|
||||||
|
size_t tlen, hlen = os_strlen(value);
|
||||||
|
if (hlen & 1)
|
||||||
|
return NULL;
|
||||||
|
tlen = hlen / 2;
|
||||||
|
str = os_malloc(tlen + 1);
|
||||||
|
if (str == NULL)
|
||||||
|
return NULL;
|
||||||
|
if (hexstr2bin(value, str, tlen)) {
|
||||||
|
os_free(str);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
str[tlen] = '\0';
|
||||||
|
*len = tlen;
|
||||||
|
return (char *) str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -446,6 +446,8 @@ size_t printf_decode(u8 *buf, size_t maxlen, const char *str);
|
|||||||
|
|
||||||
const char * wpa_ssid_txt(const u8 *ssid, size_t ssid_len);
|
const char * wpa_ssid_txt(const u8 *ssid, size_t ssid_len);
|
||||||
|
|
||||||
|
char * wpa_config_parse_string(const char *value, size_t *len);
|
||||||
|
|
||||||
static inline int is_zero_ether_addr(const u8 *a)
|
static inline int is_zero_ether_addr(const u8 *a)
|
||||||
{
|
{
|
||||||
return !(a[0] | a[1] | a[2] | a[3] | a[4] | a[5]);
|
return !(a[0] | a[1] | a[2] | a[3] | a[4] | a[5]);
|
||||||
|
@ -53,67 +53,6 @@ struct parse_data {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static char * wpa_config_parse_string(const char *value, size_t *len)
|
|
||||||
{
|
|
||||||
if (*value == '"') {
|
|
||||||
const char *pos;
|
|
||||||
char *str;
|
|
||||||
value++;
|
|
||||||
pos = os_strrchr(value, '"');
|
|
||||||
if (pos == NULL || pos[1] != '\0')
|
|
||||||
return NULL;
|
|
||||||
*len = pos - value;
|
|
||||||
str = os_malloc(*len + 1);
|
|
||||||
if (str == NULL)
|
|
||||||
return NULL;
|
|
||||||
os_memcpy(str, value, *len);
|
|
||||||
str[*len] = '\0';
|
|
||||||
return str;
|
|
||||||
} else if (*value == 'P' && value[1] == '"') {
|
|
||||||
const char *pos;
|
|
||||||
char *tstr, *str;
|
|
||||||
size_t tlen;
|
|
||||||
value += 2;
|
|
||||||
pos = os_strrchr(value, '"');
|
|
||||||
if (pos == NULL || pos[1] != '\0')
|
|
||||||
return NULL;
|
|
||||||
tlen = pos - value;
|
|
||||||
tstr = os_malloc(tlen + 1);
|
|
||||||
if (tstr == NULL)
|
|
||||||
return NULL;
|
|
||||||
os_memcpy(tstr, value, tlen);
|
|
||||||
tstr[tlen] = '\0';
|
|
||||||
|
|
||||||
str = os_malloc(tlen + 1);
|
|
||||||
if (str == NULL) {
|
|
||||||
os_free(tstr);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
*len = printf_decode((u8 *) str, tlen + 1, tstr);
|
|
||||||
os_free(tstr);
|
|
||||||
|
|
||||||
return str;
|
|
||||||
} else {
|
|
||||||
u8 *str;
|
|
||||||
size_t tlen, hlen = os_strlen(value);
|
|
||||||
if (hlen & 1)
|
|
||||||
return NULL;
|
|
||||||
tlen = hlen / 2;
|
|
||||||
str = os_malloc(tlen + 1);
|
|
||||||
if (str == NULL)
|
|
||||||
return NULL;
|
|
||||||
if (hexstr2bin(value, str, tlen)) {
|
|
||||||
os_free(str);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
str[tlen] = '\0';
|
|
||||||
*len = tlen;
|
|
||||||
return (char *) str;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int wpa_config_parse_str(const struct parse_data *data,
|
static int wpa_config_parse_str(const struct parse_data *data,
|
||||||
struct wpa_ssid *ssid,
|
struct wpa_ssid *ssid,
|
||||||
int line, const char *value)
|
int line, const char *value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user