libubus: use list_empty/list_first_entry in ubus_process_pending_msg
authorFelix Fietkau <nbd@nbd.name>
Mon, 9 Aug 2021 10:49:34 +0000 (12:49 +0200)
committerFelix Fietkau <nbd@nbd.name>
Wed, 8 Sep 2021 10:25:31 +0000 (12:25 +0200)
Simplifies checks and avoids potential list corruption on recursive calls

Signed-off-by: Felix Fietkau <nbd@nbd.name>
libubus.c

index 91f317c59867e57005618c3a94d835ff8d1d81fb..7ce454eabc648bcafccf3e6f5248c31228897b68 100644 (file)
--- a/libubus.c
+++ b/libubus.c
@@ -115,12 +115,13 @@ ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd)
 static void ubus_process_pending_msg(struct uloop_timeout *timeout)
 {
        struct ubus_context *ctx = container_of(timeout, struct ubus_context, pending_timer);
-       struct ubus_pending_msg *pending, *tmp;
+       struct ubus_pending_msg *pending;
 
-       list_for_each_entry_safe(pending, tmp, &ctx->pending, list) {
+       while (!list_empty(&ctx->pending)) {
                if (ctx->stack_depth)
                        break;
 
+               pending = list_first_entry(&ctx->pending, struct ubus_pending_msg, list);
                list_del(&pending->list);
                ubus_process_msg(ctx, &pending->hdr, -1);
                free(pending);