summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTito Brasolin2025-09-05 08:09:16 +0000
committerRobert Marko2025-12-24 10:08:44 +0000
commit506e24987b97fbc866005bfb71316bd63601a1ef (patch)
tree45dc91c7f8e6d18b3ccb9202d9f1f3052fa21ec3
parentebb92e6b339b88bbc6b76501b6603c52d4887ba1 (diff)
downloaduhttpd-master.tar.gz
ubus: unregister ubus subscriber on HTTP client disconnectHEADmaster
Fixes a potential SIGSEGV when a client disconnects from a /ubus/subscribe/... endpoint without unsubscribing. The ubus subscriber is now properly unregistered in a cleanup handler, preventing callbacks on freed client structures. Fixes: #1 Signed-off-by: Tito Brasolin <tito.brasolin@kerberos.energy> Link: https://github.com/openwrt/uhttpd/pull/18 Signed-off-by: Robert Marko <robert.marko@sartura.hr>
-rw-r--r--ubus.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/ubus.c b/ubus.c
index 99cc400..4b15466 100644
--- a/ubus.c
+++ b/ubus.c
@@ -362,6 +362,14 @@ static void uh_ubus_subscription_notification_remove_cb(struct ubus_context *ctx
ops->request_done(cl);
}
+/* Cleanup function to unregister ubus subscriber when HTTP client closes */
+static void uh_ubus_subscription_free(struct client *cl)
+{
+ struct dispatch_ubus *du = &cl->dispatch.ubus;
+ if (du->sub.obj.id)
+ ubus_unregister_subscriber(ctx, &du->sub);
+}
+
static void uh_ubus_handle_get_subscribe(struct client *cl, const char *path)
{
struct dispatch_ubus *du = &cl->dispatch.ubus;
@@ -399,6 +407,9 @@ static void uh_ubus_handle_get_subscribe(struct client *cl, const char *path)
if (conf.events_retry)
ops->chunk_printf(cl, "retry: %d\n", conf.events_retry);
+ /* Ensure cleanup on client disconnect */
+ cl->dispatch.free = uh_ubus_subscription_free;
+
return;
err_unregister: