From owner-svn-src-stable@freebsd.org Wed Jul 15 22:41:58 2020 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BB84D37224A; Wed, 15 Jul 2020 22:41:58 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4B6XSQ4Z6Qz4blG; Wed, 15 Jul 2020 22:41:58 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7FD911E528; Wed, 15 Jul 2020 22:41:58 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 06FMfwfg074781; Wed, 15 Jul 2020 22:41:58 GMT (envelope-from eugen@FreeBSD.org) Received: (from eugen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06FMfwGt074780; Wed, 15 Jul 2020 22:41:58 GMT (envelope-from eugen@FreeBSD.org) Message-Id: <202007152241.06FMfwGt074780@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eugen set sender to eugen@FreeBSD.org using -f From: Eugene Grosbein Date: Wed, 15 Jul 2020 22:41:58 +0000 (UTC) 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 X-SVN-Group: stable-12 X-SVN-Commit-Author: eugen X-SVN-Commit-Paths: stable/12/usr.sbin/newsyslog X-SVN-Commit-Revision: 363237 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jul 2020 22:41:58 -0000 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); }