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>
This commit is contained in:
David Oberhollenzer 2018-10-28 15:28:03 +01:00
parent 7dfe5f6285
commit a70b85fd64
1 changed files with 5 additions and 5 deletions

10
klogd.c
View File

@ -126,8 +126,6 @@ int main(int argc, char **argv)
sigsetup(); sigsetup();
log_open(); log_open();
/* TODO: seccomp lockdown? */
while (running) { while (running) {
diff = klogctl(KLOG_READ, log_buffer + count, diff = klogctl(KLOG_READ, log_buffer + count,
sizeof(log_buffer) - 1 - count); sizeof(log_buffer) - 1 - count);
@ -147,8 +145,10 @@ int main(int argc, char **argv)
for (;;) { for (;;) {
end = strchr(ptr, '\n'); end = strchr(ptr, '\n');
if (end == NULL) { if (end == NULL) {
count = strlen(ptr); if (ptr != log_buffer) {
memmove(log_buffer, ptr, count); count = strlen(ptr);
memmove(log_buffer, ptr, count + 1);
}
break; break;
} }
@ -163,7 +163,7 @@ int main(int argc, char **argv)
++ptr; ++ptr;
} }
if (*ptr) if (*ptr != '\0')
syslog(priority, "%s", ptr); syslog(priority, "%s", ptr);
ptr = end; ptr = end;
} }