spotfilter: fix a use-after-free

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2022-10-14 15:20:14 +02:00
committed by jaspreetsachdev
parent 9c2f0a098d
commit 41c64e9978
2 changed files with 6 additions and 3 deletions

View File

@@ -65,6 +65,7 @@ static void __client_free(struct interface *iface, struct client *cl)
avl_delete(&iface->client_ids, &cl->id_node); avl_delete(&iface->client_ids, &cl->id_node);
avl_delete(&iface->clients, &cl->node); avl_delete(&iface->clients, &cl->node);
kvlist_free(&cl->kvdata); kvlist_free(&cl->kvdata);
free(cl->device);
spotfilter_bpf_set_client(iface, &cl->key, NULL); spotfilter_bpf_set_client(iface, &cl->key, NULL);
free(cl); free(cl);
} }
@@ -143,8 +144,10 @@ int client_set(struct interface *iface, const void *addr, const char *id,
kvlist_set(&cl->kvdata, blobmsg_name(cur), cur); kvlist_set(&cl->kvdata, blobmsg_name(cur), cur);
} }
if (device) if (device) {
cl->device = device; free(cl->device);
cl->device = strdup(device);
}
if (state >= 0) if (state >= 0)
cl->data.cur_class = state; cl->data.cur_class = state;
if (dns_state >= 0) if (dns_state >= 0)

View File

@@ -17,7 +17,7 @@ struct client {
struct spotfilter_client_key key; struct spotfilter_client_key key;
struct spotfilter_client_data data; struct spotfilter_client_data data;
const char *device; char *device;
}; };
int client_set(struct interface *iface, const void *addr, const char *id, int client_set(struct interface *iface, const void *addr, const char *id,