aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/syslogd/syslogd.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
index 0acb9ffcc4781..9e080b4002951 100644
--- a/usr.sbin/syslogd/syslogd.c
+++ b/usr.sbin/syslogd/syslogd.c
@@ -645,18 +645,21 @@ usage(void)
static void
printline(const char *hname, char *msg)
{
+ char *p, *q;
+ long n;
int c, pri;
- char *p, *q, line[MAXLINE + 1];
+ char line[MAXLINE + 1];
/* test for special codes */
- pri = DEFUPRI;
p = msg;
+ pri = DEFUPRI;
if (*p == '<') {
- pri = 0;
- while (isdigit(*++p))
- pri = 10 * pri + (*p - '0');
- if (*p == '>')
- ++p;
+ errno = 0;
+ n = strtol(p + 1, &q, 10);
+ if (*q == '>' && n >= 0 && n < INT_MAX && errno == 0) {
+ p = q + 1;
+ pri = n;
+ }
}
if (pri &~ (LOG_FACMASK|LOG_PRIMASK))
pri = DEFUPRI;
@@ -736,24 +739,21 @@ readklog(void)
static void
printsys(char *msg)
{
- char *p;
- int flags, isprintf, n, pri;
+ char *p, *q;
+ long n;
+ int flags, isprintf, pri;
flags = ISKERNEL | SYNC_FILE | ADDDATE; /* fsync after write */
- pri = DEFSPRI;
p = msg;
+ pri = DEFSPRI;
isprintf = 1;
if (*p == '<') {
- n = 0;
- while (isdigit(*++p))
- n = 10 * n + (*p - '0');
- if (*p == '>') {
- ++p;
+ errno = 0;
+ n = strtol(p + 1, &q, 10);
+ if (*q == '>' && n >= 0 && n < INT_MAX && errno == 0) {
+ p = q + 1;
pri = n;
isprintf = 0;
- } else {
- /* It wasn't actually a syslog message. */
- p = msg;
}
}
/*