From 2e5426c0451ec03ef5fd6f41d7cfa26f84a857af Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 29 Jun 2022 19:37:11 +0200 Subject: ubus: end uloop on exceptions in managed code Instead of silently continuing, end the uloop when encountering exceptions in ucode callbacks to let those exceptions propagate to the host program. Signed-off-by: Jo-Philipp Wich --- lib/ubus.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/ubus.c b/lib/ubus.c index 2911d81..7f30fb8 100644 --- a/lib/ubus.c +++ b/lib/ubus.c @@ -740,6 +740,8 @@ uc_ubus_defer(uc_vm_t *vm, size_t nargs) if (uc_vm_call(vm, false, 1) == EXCEPTION_NONE) ucv_put(uc_vm_stack_pop(vm)); + else + uloop_end(); free(defer); } @@ -888,6 +890,8 @@ uc_ubus_object_notify_data_cb(struct ubus_notify_request *req, int type, struct if (uc_vm_call(notifyctx->vm, true, 2) == EXCEPTION_NONE) ucv_put(uc_vm_stack_pop(notifyctx->vm)); + else + uloop_end(); } } @@ -907,6 +911,8 @@ uc_ubus_object_notify_status_cb(struct ubus_notify_request *req, int idx, int re if (uc_vm_call(notifyctx->vm, true, 2) == EXCEPTION_NONE) ucv_put(uc_vm_stack_pop(notifyctx->vm)); + else + uloop_end(); } } @@ -926,6 +932,8 @@ uc_ubus_object_notify_complete_cb(struct ubus_notify_request *req, int idx, int if (uc_vm_call(notifyctx->vm, true, 2) == EXCEPTION_NONE) ucv_put(uc_vm_stack_pop(notifyctx->vm)); + else + uloop_end(); } notifyctx->complete = true; @@ -1203,7 +1211,6 @@ uc_ubus_handle_reply_common(struct ubus_context *ctx, callctx->registry_index = request_reg_add(vm, ucv_get(reqobj), NULL); } - /* Otherwise, when the function returned an object, treat it as * reply data and conclude deferred request immediately */ else if (ucv_type(res) == UC_OBJECT) { @@ -1238,9 +1245,10 @@ uc_ubus_handle_reply_common(struct ubus_context *ctx, callctx->replied = true; break; - /* treat other exceptions as unknown error */ + /* treat other exceptions as fatal and halt uloop */ default: ubus_complete_deferred_request(ctx, &callctx->req, UBUS_STATUS_UNKNOWN_ERROR); + uloop_end(); callctx->replied = true; break; } -- cgit v1.2.3