summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2017-11-06 11:34:31 +0100
committerFelix Fietkau <nbd@nbd.name>2017-11-06 11:34:31 +0100
commitea3d7fa21f55a39ce55d8e91058c944f5e5d9c6b (patch)
tree8bb42e2a47cfeb4b2c3d729e2d543d15235f68bd
parent4a10d4e02897be37a517bc6e016e9d722086765e (diff)
downloadubox-ea3d7fa21f55a39ce55d8e91058c944f5e5d9c6b.tar.gz
logd: enforce line length limit for ubus based log messages as well
Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--log/logd.c10
-rw-r--r--log/syslog.c6
-rw-r--r--log/syslog.h2
3 files changed, 13 insertions, 5 deletions
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,