aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-10-28 15:28:03 +0100
committerDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-10-28 15:28:03 +0100
commita70b85fd641aa1845d7d028ca4192773c4de5459 (patch)
tree584d19c426ae5d4f98a41f4f64af6ff3b69b9251
parent7dfe5f62855eed985f9710024c4bace9e8a251d1 (diff)
minor klogd fixes
when copying the left over stub, always make sure we copy the null terminator as well. Theoretically shouldn't be a problem since we exit the inner loop anyway and then append to the buffer and add a new null terminator, but just to be safe, make sure the buffer is *ALWAYS* null-terminated. When we are at it, skip the buffer copy if we didn't consume any input and actually compare the value against '\0' instead of just testing for *ptr (readabillity). Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
-rw-r--r--klogd.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/klogd.c b/klogd.c
index 8db1d50..c9f551b 100644
--- a/klogd.c
+++ b/klogd.c
@@ -126,8 +126,6 @@ int main(int argc, char **argv)
sigsetup();
log_open();
- /* TODO: seccomp lockdown? */
-
while (running) {
diff = klogctl(KLOG_READ, log_buffer + count,
sizeof(log_buffer) - 1 - count);
@@ -147,8 +145,10 @@ int main(int argc, char **argv)
for (;;) {
end = strchr(ptr, '\n');
if (end == NULL) {
- count = strlen(ptr);
- memmove(log_buffer, ptr, count);
+ if (ptr != log_buffer) {
+ count = strlen(ptr);
+ memmove(log_buffer, ptr, count + 1);
+ }
break;
}
@@ -163,7 +163,7 @@ int main(int argc, char **argv)
++ptr;
}
- if (*ptr)
+ if (*ptr != '\0')
syslog(priority, "%s", ptr);
ptr = end;
}