logd: prevent the buffer from being bigger than the maximum ubus size
authorJohn Crispin <blogic@openwrt.org>
Tue, 21 Jan 2014 13:00:19 +0000 (13:00 +0000)
committerJohn Crispin <blogic@openwrt.org>
Tue, 21 Jan 2014 13:02:18 +0000 (13:02 +0000)
Signed-off-by: John Crispin <blogic@openwrt.org>
log/syslog.c

index 4cabb434a0ea050e7d79452566807a66d4c51eae..d0b528d6c7b4bf6f42aeffb08e6a2f8b774a7271 100644 (file)
@@ -30,6 +30,8 @@
 #include <libubox/usock.h>
 #include <libubox/ustream.h>
 
+#include <ubusmsg.h>
+
 #include "syslog.h"
 
 #define LOG_DEFAULT_SIZE       (16 * 1024)
@@ -279,6 +281,10 @@ log_init(int _log_size)
        if (_log_size > 0)
                log_size = _log_size;
 
+       /* reserve 512 bytes for protocol overhead */
+       if (log_size > (UBUS_MAX_MSGLEN -  512))
+               log_size = UBUS_MAX_MSGLEN - 512;
+
        regcomp(&pat_prio, "^<([0-9]*)>(.*)", REG_EXTENDED);
        regcomp(&pat_tstamp, "^\[[ 0]*([0-9]*).([0-9]*)] (.*)", REG_EXTENDED);