From owner-svn-src-all@freebsd.org Tue Nov 3 11:37:19 2020 Return-Path: Delivered-To: svn-src-all@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 D33A7455980; Tue, 3 Nov 2020 11:37:19 +0000 (UTC) (envelope-from se@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 4CQSSH5DMhz3WDc; Tue, 3 Nov 2020 11:37:19 +0000 (UTC) (envelope-from se@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 96EC419CF8; Tue, 3 Nov 2020 11:37:19 +0000 (UTC) (envelope-from se@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0A3BbJ9H026067; Tue, 3 Nov 2020 11:37:19 GMT (envelope-from se@FreeBSD.org) Received: (from se@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0A3BbJLh026066; Tue, 3 Nov 2020 11:37:19 GMT (envelope-from se@FreeBSD.org) Message-Id: <202011031137.0A3BbJLh026066@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: se set sender to se@FreeBSD.org using -f From: =?UTF-8?Q?Stefan_E=c3=9fer?= Date: Tue, 3 Nov 2020 11:37:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367292 - head/usr.bin/calendar X-SVN-Group: head X-SVN-Commit-Author: se X-SVN-Commit-Paths: head/usr.bin/calendar X-SVN-Commit-Revision: 367292 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Nov 2020 11:37:19 -0000 Author: se Date: Tue Nov 3 11:37:19 2020 New Revision: 367292 URL: https://svnweb.freebsd.org/changeset/base/367292 Log: Check that #ifdef, #ifndef, and #undef are used with a single name This restores the parameter validation that has been peformed by cpp for defining and testing of names used in conditions. MFC after: 3 days Modified: head/usr.bin/calendar/io.c Modified: head/usr.bin/calendar/io.c ============================================================================== --- head/usr.bin/calendar/io.c Tue Nov 3 10:02:52 2020 (r367291) +++ head/usr.bin/calendar/io.c Tue Nov 3 11:37:19 2020 (r367292) @@ -89,22 +89,29 @@ static StringList *definitions = NULL; static struct event *events[MAXCOUNT]; static char *extradata[MAXCOUNT]; -static void +static char * trimlr(char **buf) { char *walk = *buf; + char *sep; char *last; while (isspace(*walk)) walk++; - if (*walk != '\0') { - last = walk + strlen(walk) - 1; + *buf = walk; + + sep = walk; + while (*sep != '\0' && !isspace(*sep)) + sep++; + + if (*sep != '\0') { + last = sep + strlen(sep) - 1; while (last > walk && isspace(*last)) last--; *(last+1) = 0; } - *buf = walk; + return (sep); } static FILE * @@ -167,7 +174,7 @@ cal_path(void) static int token(char *line, FILE *out, int *skip, int *unskip) { - char *walk, c, a; + char *walk, *sep, a, c; const char *this_cal_home; const char *this_cal_dir; const char *this_cal_file; @@ -188,14 +195,20 @@ token(char *line, FILE *out, int *skip, int *unskip) if (strncmp(line, "ifdef", 5) == 0) { walk = line + 5; - trimlr(&walk); + sep = trimlr(&walk); if (*walk == '\0') { WARN0("Expecting arguments after #ifdef"); return (T_ERR); } + if (*sep != '\0') { + WARN1("Expecting a single word after #ifdef " + "but got \"%s\"", walk); + return (T_ERR); + } - if (*skip != 0 || definitions == NULL || sl_find(definitions, walk) == NULL) + if (*skip != 0 || + definitions == NULL || sl_find(definitions, walk) == NULL) ++*skip; else ++*unskip; @@ -205,14 +218,20 @@ token(char *line, FILE *out, int *skip, int *unskip) if (strncmp(line, "ifndef", 6) == 0) { walk = line + 6; - trimlr(&walk); + sep = trimlr(&walk); if (*walk == '\0') { WARN0("Expecting arguments after #ifndef"); return (T_ERR); } + if (*sep != '\0') { + WARN1("Expecting a single word after #ifndef " + "but got \"%s\"", walk); + return (T_ERR); + } - if (*skip != 0 || (definitions != NULL && sl_find(definitions, walk) != NULL)) + if (*skip != 0 || + (definitions != NULL && sl_find(definitions, walk) != NULL)) ++*skip; else ++*unskip; @@ -222,7 +241,7 @@ token(char *line, FILE *out, int *skip, int *unskip) if (strncmp(line, "else", 4) == 0) { walk = line + 4; - trimlr(&walk); + (void)trimlr(&walk); if (*walk != '\0') { WARN0("Expecting no arguments after #else"); @@ -251,7 +270,7 @@ token(char *line, FILE *out, int *skip, int *unskip) if (strncmp(line, "include", 7) == 0) { walk = line + 7; - trimlr(&walk); + (void)trimlr(&walk); if (*walk == '\0') { WARN0("Expecting arguments after #include"); @@ -291,7 +310,8 @@ token(char *line, FILE *out, int *skip, int *unskip) if (definitions == NULL) definitions = sl_init(); walk = line + 6; - trimlr(&walk); + sep = trimlr(&walk); + *sep = '\0'; if (*walk == '\0') { WARN0("Expecting arguments after #define"); @@ -306,10 +326,15 @@ token(char *line, FILE *out, int *skip, int *unskip) if (strncmp(line, "undef", 5) == 0) { if (definitions != NULL) { walk = line + 5; - trimlr(&walk); + sep = trimlr(&walk); if (*walk == '\0') { WARN0("Expecting arguments after #undef"); + return (T_ERR); + } + if (*sep != '\0') { + WARN1("Expecting a single word after #undef " + "but got \"%s\"", walk); return (T_ERR); }