fix 32 wrap around bug when handling 64 bit time values
authorJohn Crispin <blogic@openwrt.org>
Thu, 25 Apr 2013 19:37:25 +0000 (21:37 +0200)
committerJohn Crispin <blogic@openwrt.org>
Thu, 25 Apr 2013 19:40:08 +0000 (21:40 +0200)
Signed-off-by: John Crispin <blogic@openwrt.org>
log.c
logread.c

diff --git a/log.c b/log.c
index d2a71588fda4563c2fd6f4307232d7f92a079052..82fb8f87fdfa4e3182a0ad7d5ff20779c5713e2d 100644 (file)
--- a/log.c
+++ b/log.c
@@ -12,6 +12,8 @@
  * GNU General Public License for more details.
  */
 
+#include <linux/types.h>
+
 #include <libubox/uloop.h>
 #include <libubox/blobmsg_json.h>
 
@@ -56,7 +58,7 @@ static int read_log(struct ubus_context *ctx, struct ubus_object *obj,
                blobmsg_add_u32(&b, "id", l->id);
                blobmsg_add_u32(&b, "priority", l->priority);
                blobmsg_add_u32(&b, "source", l->source);
-               blobmsg_add_u64(&b, "time", (l->ts.tv_sec * 1000) + (l->ts.tv_nsec / 1000000));
+               blobmsg_add_u64(&b, "time", l->ts.tv_sec);
                blobmsg_close_table(&b, entry);
                l = log_list(count, l);
        }
@@ -116,7 +118,7 @@ void ubus_notify_log(struct log_head *l)
        blobmsg_add_u32(&b, "id", l->id);
        blobmsg_add_u32(&b, "priority", l->priority);
        blobmsg_add_u32(&b, "source", l->source);
-       blobmsg_add_u64(&b, "time", (l->ts.tv_sec * 1000) + (l->ts.tv_nsec / 1000000));
+       blobmsg_add_u64(&b, "time", (((__u64) l->ts.tv_sec) * 1000) + (l->ts.tv_nsec / 1000000));
 
        ret = ubus_notify(_ctx, &log_object, l->data, b.head, -1);
        if (ret)
index b7f9ebeebae9223d11dc50061530540708b942ad..2a0ffdece4ad8224c5c16878047b6f6babca73e5 100644 (file)
--- a/logread.c
+++ b/logread.c
@@ -130,7 +130,7 @@ static void read_cb(struct ubus_request *req, int type, struct blob_attr *msg)
                if (!tb[LOG_MSG] || !tb[LOG_ID] || !tb[LOG_PRIO] || !tb[LOG_SOURCE] || !tb[LOG_TIME])
                        continue;
 
-               t = blobmsg_get_u64(tb[LOG_TIME]) / 1000;
+               t = blobmsg_get_u64(tb[LOG_TIME]);
                c = ctime(&t);
                c[strlen(c) - 1] = '\0';
                printf("%s - %s: %s\n",