Date: Wed, 15 Jul 2020 22:41:58 +0000 (UTC) From: Eugene Grosbein <eugen@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r363237 - stable/12/usr.sbin/newsyslog Message-ID: <202007152241.06FMfwGt074780@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: eugen Date: Wed Jul 15 22:41:58 2020 New Revision: 363237 URL: https://svnweb.freebsd.org/changeset/base/363237 Log: MFC r362233: newsyslog(8): make configuration parser more robust. Modified: stable/12/usr.sbin/newsyslog/newsyslog.c Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.sbin/newsyslog/newsyslog.c ============================================================================== --- stable/12/usr.sbin/newsyslog/newsyslog.c Wed Jul 15 19:34:19 2020 (r363236) +++ stable/12/usr.sbin/newsyslog/newsyslog.c Wed Jul 15 22:41:58 2020 (r363237) @@ -1078,9 +1078,11 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl q = parse = missing_field(sob(line), errline); parse = son(line); - if (!*parse) - errx(1, "malformed line (missing fields):\n%s", + if (!*parse) { + warnx("malformed line (missing fields):\n%s", errline); + continue; + } *parse = '\0'; /* @@ -1132,22 +1134,24 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl continue; } +#define badline(msg, ...) do { \ + warnx(msg, __VA_ARGS__); \ + goto cleanup; \ +} while (0) + special = 0; working = init_entry(q, NULL); if (strcasecmp(DEFAULT_MARKER, q) == 0) { special = 1; - if (*defconf_p != NULL) { - warnx("Ignoring duplicate entry for %s!", q); - free_entry(working); - continue; - } + if (*defconf_p != NULL) + badline("Ignoring duplicate entry for %s!", q); *defconf_p = working; } q = parse = missing_field(sob(parse + 1), errline); parse = son(parse); if (!*parse) - errx(1, "malformed line (missing fields):\n%s", + badline("malformed line (missing fields):\n%s", errline); *parse = '\0'; if ((group = strchr(q, ':')) != NULL || @@ -1156,7 +1160,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl if (*q) { if (!(isnumberstr(q))) { if ((pwd = getpwnam(q)) == NULL) - errx(1, + badline( "error in config file; unknown user:\n%s", errline); working->uid = pwd->pw_uid; @@ -1169,7 +1173,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl if (*q) { if (!(isnumberstr(q))) { if ((grp = getgrnam(q)) == NULL) - errx(1, + badline( "error in config file; unknown group:\n%s", errline); working->gid = grp->gr_gid; @@ -1181,7 +1185,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl q = parse = missing_field(sob(parse + 1), errline); parse = son(parse); if (!*parse) - errx(1, "malformed line (missing fields):\n%s", + badline("malformed line (missing fields):\n%s", errline); *parse = '\0'; } else { @@ -1190,7 +1194,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl } if (!sscanf(q, "%o", &working->permissions)) - errx(1, "error in config file; bad permissions:\n%s", + badline("error in config file; bad permissions:\n%s", errline); if ((working->permissions & ~DEFFILEMODE) != 0) { warnx("File mode bits 0%o changed to 0%o in line:\n%s", @@ -1202,17 +1206,17 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl q = parse = missing_field(sob(parse + 1), errline); parse = son(parse); if (!*parse) - errx(1, "malformed line (missing fields):\n%s", + badline("malformed line (missing fields):\n%s", errline); *parse = '\0'; if (!sscanf(q, "%d", &working->numlogs) || working->numlogs < 0) - errx(1, "error in config file; bad value for count of logs to save:\n%s", + badline("error in config file; bad value for count of logs to save:\n%s", errline); q = parse = missing_field(sob(parse + 1), errline); parse = son(parse); if (!*parse) - errx(1, "malformed line (missing fields):\n%s", + badline("malformed line (missing fields):\n%s", errline); *parse = '\0'; if (isdigitch(*q)) @@ -1241,14 +1245,14 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl else if (*ep == '*') working->hours = -1; else if (ul > INT_MAX) - errx(1, "interval is too large:\n%s", errline); + badline("interval is too large:\n%s", errline); else working->hours = ul; if (*ep == '\0' || strcmp(ep, "*") == 0) goto no_trimat; if (*ep != '@' && *ep != '$') - errx(1, "malformed interval/at:\n%s", errline); + badline("malformed interval/at:\n%s", errline); working->flags |= CE_TRIMAT; working->trim_at = ptime_init(NULL); @@ -1259,10 +1263,10 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl res = ptime_relparse(working->trim_at, ptm_opts, ptimeget_secs(timenow), ep + 1); if (res == -2) - errx(1, "nonexistent time for 'at' value:\n%s", + badline("nonexistent time for 'at' value:\n%s", errline); else if (res < 0) - errx(1, "malformed 'at' value:\n%s", errline); + badline("malformed 'at' value:\n%s", errline); } no_trimat: @@ -1325,7 +1329,7 @@ no_trimat: case 'f': /* Used by OpenBSD for "CE_FOLLOW" */ case 'm': /* Used by OpenBSD for "CE_MONITOR" */ default: - errx(1, "illegal flag in config file -- %c", + badline("illegal flag in config file -- %c", *q); } } @@ -1347,7 +1351,7 @@ no_trimat: else if (isalnum(*q)) goto got_sig; else { - errx(1, + badline( "illegal pid file or signal in config file:\n%s", errline); } @@ -1365,7 +1369,7 @@ no_trimat: got_sig: working->sig = parse_signal(q); if (working->sig < 1 || working->sig >= sys_nsig) { - errx(1, + badline( "illegal signal in config file:\n%s", errline); } @@ -1416,7 +1420,11 @@ got_sig: } else { STAILQ_INSERT_TAIL(work_p, working, cf_nextp); } - } + continue; +cleanup: + free_entry(working); +#undef badline + } /* while (fgets(line, BUFSIZ, cf)) */ if (errline != NULL) free(errline); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202007152241.06FMfwGt074780>