logread: ensure that the len < sizeof(struct blob_attr) check runs before trying...
authorFelix Fietkau <nbd@openwrt.org>
Sun, 24 Jan 2016 08:19:53 +0000 (09:19 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 24 Jan 2016 08:19:53 +0000 (09:19 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
log/logread.c

index dcf3c08a624d5d57eda56dd6f65a1cb56439dca4..83b74b1f6b752c925d1f1a295062b1104da9ef15 100644 (file)
@@ -208,14 +208,19 @@ static int usage(const char *prog)
 static void logread_fd_data_cb(struct ustream *s, int bytes)
 {
        while (true) {
-               int len;
                struct blob_attr *a;
+               int len, cur_len;
 
                a = (void*) ustream_get_read_buf(s, &len);
-               if (len < sizeof(*a) || len < blob_len(a) + sizeof(*a))
+               if (len < sizeof(*a))
                        break;
+
+               cur_len = blob_len(a) + sizeof(*a);
+               if (len < cur_len)
+                       break;
+
                log_notify(a);
-               ustream_consume(s, blob_len(a) + sizeof(*a));
+               ustream_consume(s, cur_len);
        }
        if (!log_follow)
                uloop_end();