Merge pull request #52 from meta-ed/overread

Prevent overread when scanning the message buffer

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg 2022-06-17 18:16:28 +02:00 committed by GitHub
commit 2d37cf2c28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1321,11 +1321,12 @@ void printsys(char *msg)
if (*p == '<') { if (*p == '<') {
/* /proc/klog or *BSD /dev/klog */ /* /proc/klog or *BSD /dev/klog */
p++;
buffer.pri = 0; buffer.pri = 0;
while (isdigit(*++p)) while (isdigit(*p))
buffer.pri = 10 * buffer.pri + (*p - '0'); buffer.pri = 10 * buffer.pri + (*p++ - '0');
if (*p == '>') if (*p == '>')
++p; p++;
} else if (isdigit(*p)) { } else if (isdigit(*p)) {
/* Linux /dev/kmsg: "pri,seq#,msec,flag[,..];msg" */ /* Linux /dev/kmsg: "pri,seq#,msec,flag[,..];msg" */
time_t now; time_t now;
@ -1334,8 +1335,8 @@ void printsys(char *msg)
buffer.pri = 0; buffer.pri = 0;
while (isdigit(*p)) while (isdigit(*p))
buffer.pri = 10 * buffer.pri + (*p++ - '0'); buffer.pri = 10 * buffer.pri + (*p++ - '0');
if (*p == ',')
p++; /* skip ',' */ p++;
/* seq# */ /* seq# */
while (isdigit(*p)) while (isdigit(*p))
@ -1351,8 +1352,8 @@ void printsys(char *msg)
return; return;
} }
sys_seqno = seqno; sys_seqno = seqno;
if (*p == ',')
p++; /* skip ',' */ p++;
/* timestamp */ /* timestamp */
while (isdigit(*p)) while (isdigit(*p))