Improve p2p_client_list updates in configuration file

This list can get truncated due to too many addresses getting added.
Reorder the entries in a way that allows the most recently added values
to be maintained in the list and use better debug/error messages when
parsing the value.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
intended-for: hostap-1
This commit is contained in:
Jouni Malinen 2012-08-23 23:56:51 +03:00 committed by Jouni Malinen
parent d42bc5e178
commit 223167956c
2 changed files with 40 additions and 16 deletions

View file

@ -1376,10 +1376,18 @@ static int wpa_config_parse_p2p_client_list(const struct parse_data *data,
pos++; pos++;
if (hwaddr_aton(pos, addr)) { if (hwaddr_aton(pos, addr)) {
if (count == 0) {
wpa_printf(MSG_ERROR, "Line %d: Invalid " wpa_printf(MSG_ERROR, "Line %d: Invalid "
"p2p_client_list address '%s'.", "p2p_client_list address '%s'.",
line, value); line, value);
/* continue anyway */ os_free(buf);
return -1;
}
/* continue anyway since this could have been from a
* truncated configuration file line */
wpa_printf(MSG_INFO, "Line %d: Ignore likely "
"truncated p2p_client_list address '%s'",
line, pos);
} else { } else {
n = os_realloc_array(buf, count + 1, ETH_ALEN); n = os_realloc_array(buf, count + 1, ETH_ALEN);
if (n == NULL) { if (n == NULL) {
@ -1387,7 +1395,8 @@ static int wpa_config_parse_p2p_client_list(const struct parse_data *data,
return -1; return -1;
} }
buf = n; buf = n;
os_memcpy(buf + count * ETH_ALEN, addr, ETH_ALEN); os_memmove(buf + ETH_ALEN, buf, count * ETH_ALEN);
os_memcpy(buf, addr, ETH_ALEN);
count++; count++;
wpa_hexdump(MSG_MSGDUMP, "p2p_client_list", wpa_hexdump(MSG_MSGDUMP, "p2p_client_list",
addr, ETH_ALEN); addr, ETH_ALEN);
@ -1421,10 +1430,10 @@ static char * wpa_config_write_p2p_client_list(const struct parse_data *data,
pos = value; pos = value;
end = value + 20 * ssid->num_p2p_clients; end = value + 20 * ssid->num_p2p_clients;
for (i = 0; i < ssid->num_p2p_clients; i++) { for (i = ssid->num_p2p_clients; i > 0; i--) {
res = os_snprintf(pos, end - pos, MACSTR " ", res = os_snprintf(pos, end - pos, MACSTR " ",
MAC2STR(ssid->p2p_client_list + MAC2STR(ssid->p2p_client_list +
i * ETH_ALEN)); (i - 1) * ETH_ALEN));
if (res < 0 || res >= end - pos) { if (res < 0 || res >= end - pos) {
os_free(value); os_free(value);
return NULL; return NULL;

View file

@ -523,6 +523,7 @@ static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid, *s; struct wpa_ssid *ssid, *s;
u8 *n; u8 *n;
size_t i; size_t i;
int found = 0;
ssid = wpa_s->current_ssid; ssid = wpa_s->current_ssid;
if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
@ -543,17 +544,31 @@ static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant *wpa_s,
for (i = 0; s->p2p_client_list && i < s->num_p2p_clients; i++) { for (i = 0; s->p2p_client_list && i < s->num_p2p_clients; i++) {
if (os_memcmp(s->p2p_client_list + i * ETH_ALEN, addr, if (os_memcmp(s->p2p_client_list + i * ETH_ALEN, addr,
ETH_ALEN) == 0) ETH_ALEN) != 0)
return; /* already in list */ continue;
if (i == s->num_p2p_clients - 1)
return; /* already the most recent entry */
/* move the entry to mark it most recent */
os_memmove(s->p2p_client_list + i * ETH_ALEN,
s->p2p_client_list + (i + 1) * ETH_ALEN,
(s->num_p2p_clients - i - 1) * ETH_ALEN);
os_memcpy(s->p2p_client_list +
(s->num_p2p_clients - 1) * ETH_ALEN, addr, ETH_ALEN);
found = 1;
break;
} }
n = os_realloc_array(s->p2p_client_list, s->num_p2p_clients + 1, if (!found) {
ETH_ALEN); n = os_realloc_array(s->p2p_client_list,
s->num_p2p_clients + 1, ETH_ALEN);
if (n == NULL) if (n == NULL)
return; return;
os_memcpy(n + s->num_p2p_clients * ETH_ALEN, addr, ETH_ALEN); os_memcpy(n + s->num_p2p_clients * ETH_ALEN, addr, ETH_ALEN);
s->p2p_client_list = n; s->p2p_client_list = n;
s->num_p2p_clients++; s->num_p2p_clients++;
}
#ifndef CONFIG_NO_CONFIG_WRITE #ifndef CONFIG_NO_CONFIG_WRITE
if (wpa_s->parent->conf->update_config && if (wpa_s->parent->conf->update_config &&