diff options
author | 2015-03-30 09:21:42 +0000 | |
---|---|---|
committer | 2015-03-30 09:21:42 +0000 | |
commit | 7ea0a60a25bbc63ed281710e1dd05ab6b0637acb (patch) | |
tree | 5871aa9703d7cb523a3c5cd2863102b65754fc11 /usr.sbin/syslogd/syslogd.c | |
parent | Do not include <machine/autoconf.h>, for it is a kernel-only header and libkvm (diff) | |
download | wireguard-openbsd-7ea0a60a25bbc63ed281710e1dd05ab6b0637acb.tar.xz wireguard-openbsd-7ea0a60a25bbc63ed281710e1dd05ab6b0637acb.zip |
Use getline instead of fgets to allow arbitrary line length in
configuration file. Also make sure that we fully parsed it.
If not, avoid to start a half-baked syslogd.
with input by and ok bluhm@
Diffstat (limited to 'usr.sbin/syslogd/syslogd.c')
-rw-r--r-- | usr.sbin/syslogd/syslogd.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 7ac5701c7fc..9d65df759e6 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syslogd.c,v 1.160 2015/02/24 01:29:49 bluhm Exp $ */ +/* $OpenBSD: syslogd.c,v 1.161 2015/03/30 09:21:42 tobias Exp $ */ /* * Copyright (c) 1983, 1988, 1993, 1994 @@ -1591,11 +1591,12 @@ die(int signo) void init(void) { - char cline[LINE_MAX], prog[NAME_MAX+1], *p; + char prog[NAME_MAX+1], *cline, *p; struct filed_list mb; struct filed *f, *m; FILE *cf; int i; + size_t s; dprintf("init\n"); @@ -1661,9 +1662,10 @@ init(void) /* * Foreach line in the conf table, open that file. */ - f = NULL; + cline = NULL; + s = 0; strlcpy(prog, "*", sizeof(prog)); - while (fgets(cline, sizeof(cline), cf) != NULL) { + while (getline(&cline, &s, cf) != -1) { /* * check for end-of-section, comments, strip off trailing * spaces and newline character. !prog is treated @@ -1702,6 +1704,11 @@ init(void) if (f != NULL) SIMPLEQ_INSERT_TAIL(&Files, f, f_next); } + free(cline); + if (!feof(cf)) { + logerror("Unable to read config file"); + die(0); + } /* Match and initialize the memory buffers */ SIMPLEQ_FOREACH(f, &Files, f_next) { |