From: Felix Fietkau Date: Mon, 6 Nov 2017 10:34:31 +0000 (+0100) Subject: logd: enforce line length limit for ubus based log messages as well X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ea3d7fa21f55a39ce55d8e91058c944f5e5d9c6b;p=oweals%2Fubox.git logd: enforce line length limit for ubus based log messages as well Signed-off-by: Felix Fietkau --- diff --git a/log/logd.c b/log/logd.c index ee30984..9931723 100644 --- a/log/logd.c +++ b/log/logd.c @@ -167,10 +167,18 @@ write_log(struct ubus_context *ctx, struct ubus_object *obj, char *event; if (msg) { + int len; + blobmsg_parse(&write_policy, 1, &tb, blob_data(msg), blob_len(msg)); if (tb) { event = blobmsg_get_string(tb); - log_add(event, strlen(event) + 1, SOURCE_SYSLOG); + len = strlen(event) + 1; + if (len > LOG_LINE_SIZE) { + len = LOG_LINE_SIZE; + event[len - 1] = 0; + } + + log_add(event, len, SOURCE_SYSLOG); } } diff --git a/log/syslog.c b/log/syslog.c index f1c7606..7e98d36 100644 --- a/log/syslog.c +++ b/log/syslog.c @@ -37,8 +37,6 @@ #define LOG_DEFAULT_SOCKET "/dev/log" #define SYSLOG_PADDING 16 -#define MAXLINE 1024 - #define KLOG_DEFAULT_PROC "/proc/kmsg" #define PAD(x) (x % 4) ? (((x) - (x % 4)) + 4) : (x) @@ -133,13 +131,13 @@ log_add(char *buf, int size, int source) static void syslog_handle_fd(struct uloop_fd *fd, unsigned int events) { - static char buf[MAXLINE]; + static char buf[LOG_LINE_SIZE]; int len; while (1) { char *c; - len = recv(fd->fd, buf, MAXLINE - 1, 0); + len = recv(fd->fd, buf, LOG_LINE_SIZE - 1, 0); if (len < 0) { if (errno == EINTR) continue; diff --git a/log/syslog.h b/log/syslog.h index 81a039f..56ccbb9 100644 --- a/log/syslog.h +++ b/log/syslog.h @@ -14,6 +14,8 @@ #ifndef __SYSLOG_H #define __SYSLOG_H +#define LOG_LINE_SIZE 1024 + enum { SOURCE_KLOG = 0, SOURCE_SYSLOG = 1,