procd: fix container deletion
authorDaniel Golle <daniel@makrotopia.org>
Wed, 15 Sep 2021 20:29:23 +0000 (21:29 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Wed, 15 Sep 2021 20:43:23 +0000 (21:43 +0100)
Deleting a container could lead to an attempt NULL-pointer dereference
crashing procd and triggering a reboot of the system.
Properly handle service deletion to avoid that.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
service/service.c
service/service.h

index 419f96cdf422447f06893148c0cddc50a80d52cc..48825c327063dfd0ce860df9e73c95028be2112d 100644 (file)
@@ -182,8 +182,6 @@ service_update(struct service *s, struct blob_attr **tb, bool add)
        return 0;
 }
 
-static void _service_stopped(struct service *s, bool container);
-
 static void
 service_delete(struct service *s, bool container)
 {
@@ -191,7 +189,7 @@ service_delete(struct service *s, bool container)
        free(s->data);
        vlist_flush_all(&s->instances);
        s->deleted = true;
-       _service_stopped(s, container);
+       service_stopped(s);
 }
 
 enum {
@@ -430,6 +428,8 @@ service_handle_set(struct ubus_context *ctx, struct ubus_object *obj,
        if (!s)
                return UBUS_STATUS_UNKNOWN_ERROR;
 
+       s->container = container;
+
        ret = service_update(s, tb, add);
        if (ret)
                return ret;
@@ -1008,14 +1008,9 @@ service_start_early(char *name, char *cmdline, char *user, char *group)
 }
 
 void service_stopped(struct service *s)
-{
-       _service_stopped(s, false);
-}
-
-static void _service_stopped(struct service *s, bool container)
 {
        if (s->deleted && avl_is_empty(&s->instances.avl)) {
-               if (container) {
+               if (s->container) {
                        service_event("container.stop", s->name, NULL);
                        avl_delete(&containers, &s->avl);
                } else {
index 48157ccde051f7d3a4579b94f7ef00b08c69432e..e148369d3156effb7c1db49af74ad02fc59df909 100644 (file)
@@ -44,6 +44,7 @@ struct service {
        const char *name;
        bool deleted;
        bool autostart;
+       bool container;
 
        struct blob_attr *trigger;
        struct vlist_tree instances;