From 30a3f7ad0433be059f744c974917bc589b928682 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 10 Jan 2024 09:18:59 +0100 Subject: rtnl: store callback in listener registry only on success Only store the callback reference in the registry once the listener context was successfully initialized, to avoid keeping a lingering entry when invalid parameters are passed. Signed-off-by: Jo-Philipp Wich --- lib/rtnl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/rtnl.c b/lib/rtnl.c index b6add37..663e634 100644 --- a/lib/rtnl.c +++ b/lib/rtnl.c @@ -3707,9 +3707,9 @@ uc_nl_listener(uc_vm_t *vm, size_t nargs) break; } - ucv_array_set(listener_registry, i + 1, ucv_get(cb_func)); l = xalloc(sizeof(*l)); l->index = i; + if (!uc_nl_fill_cmds(l->cmds, cmds)) { uc_vm_raise_exception(vm, EXCEPTION_TYPE, "Invalid command ID"); free(l); @@ -3717,7 +3717,10 @@ uc_nl_listener(uc_vm_t *vm, size_t nargs) } rv = uc_resource_new(listener_type, l); + ucv_array_set(listener_registry, i, ucv_get(rv)); + ucv_array_set(listener_registry, i + 1, ucv_get(cb_func)); + listener_vm = vm; return rv; -- cgit v1.2.3