From owner-dev-commits-src-branches@freebsd.org Tue May 18 06:15:29 2021 Return-Path: Delivered-To: dev-commits-src-branches@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 54A3D640E92; Tue, 18 May 2021 06:15:29 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Fkm2T20Tfz3FyR; Tue, 18 May 2021 06:15:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2D9DF1A34E; Tue, 18 May 2021 06:15:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 14I6FTLd072415; Tue, 18 May 2021 06:15:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14I6FTUT072414; Tue, 18 May 2021 06:15:29 GMT (envelope-from git) Date: Tue, 18 May 2021 06:15:29 GMT Message-Id: <202105180615.14I6FTUT072414@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Lutz Donnerhacke Subject: git: 8addaaa5fb86 - stable/12 - sbin/ipfw: Fix parsing error in table based forward MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: donner X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 8addaaa5fb864190882dfcf1a1ad3d7af802dd35 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 May 2021 06:15:29 -0000 The branch stable/12 has been updated by donner: URL: https://cgit.FreeBSD.org/src/commit/?id=8addaaa5fb864190882dfcf1a1ad3d7af802dd35 commit 8addaaa5fb864190882dfcf1a1ad3d7af802dd35 Author: Lutz Donnerhacke AuthorDate: 2021-05-07 18:59:34 +0000 Commit: Lutz Donnerhacke CommitDate: 2021-05-18 06:14:25 +0000 sbin/ipfw: Fix parsing error in table based forward The argument parser does not recognise the optional port for an "tablearg" argument. Fix simplifies the code by make the internal representation expicit for the parser. Includes the fix from D30208. PR: 252744 Reported by: Approved by: nc Tested by: Differential Revision: https://reviews.freebsd.org/D30164 (cherry picked from commit 6cb13813caa09305046e0cecad8bba3ae2287b0d) (cherry picked from commit f6f297871d469daf808f78faead8f950a2c81e36) --- sbin/ipfw/ipfw2.c | 88 +++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 45 deletions(-) diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c index efb29403b6c9..8f06563d61a8 100644 --- a/sbin/ipfw/ipfw2.c +++ b/sbin/ipfw/ipfw2.c @@ -4021,57 +4021,55 @@ chkarg: NEED1("missing forward address[:port]"); - if (_substrcmp(*av, "tablearg") == 0) { - family = PF_INET; - ((struct sockaddr_in*)&result)->sin_addr.s_addr = - INADDR_ANY; - } else { - /* - * Are we an bracket-enclosed IPv6 address? - */ - if (strchr(*av, '[')) - (*av)++; + if (strncmp(*av, "tablearg", 8) == 0 && + ((*av)[8] == '\0' || (*av)[8] == ',' || (*av)[8] == ':')) + memcpy(++(*av), "0.0.0.0", 7); - /* - * locate the address-port separator (':' or ',') - */ - s = strchr(*av, ','); - if (s == NULL) { - s = strchr(*av, ']'); - /* Prevent erroneous parsing on brackets. */ - if (s != NULL) - *(s++) = '\0'; - else - s = *av; - - /* Distinguish between IPv4:port and IPv6 cases. */ - s = strchr(s, ':'); - if (s && strchr(s+1, ':')) - s = NULL; /* no port */ - } + /* + * Are we an bracket-enclosed IPv6 address? + */ + if (strchr(*av, '[')) + (*av)++; - if (s != NULL) { - /* Terminate host portion and set s to start of port. */ + /* + * locate the address-port separator (':' or ',') + */ + s = strchr(*av, ','); + if (s == NULL) { + s = strchr(*av, ']'); + /* Prevent erroneous parsing on brackets. */ + if (s != NULL) *(s++) = '\0'; - i = strtoport(s, &end, 0 /* base */, 0 /* proto */); - if (s == end) - errx(EX_DATAERR, - "illegal forwarding port ``%s''", s); - port_number = (u_short)i; - } + else + s = *av; - /* - * Resolve the host name or address to a family and a - * network representation of the address. - */ - if (getaddrinfo(*av, NULL, NULL, &res)) - errx(EX_DATAERR, NULL); - /* Just use the first host in the answer. */ - family = res->ai_family; - memcpy(&result, res->ai_addr, res->ai_addrlen); - freeaddrinfo(res); + /* Distinguish between IPv4:port and IPv6 cases. */ + s = strchr(s, ':'); + if (s && strchr(s+1, ':')) + s = NULL; /* no port */ } + if (s != NULL) { + /* Terminate host portion and set s to start of port. */ + *(s++) = '\0'; + i = strtoport(s, &end, 0 /* base */, 0 /* proto */); + if (s == end) + errx(EX_DATAERR, + "illegal forwarding port ``%s''", s); + port_number = (u_short)i; + } + + /* + * Resolve the host name or address to a family and a + * network representation of the address. + */ + if (getaddrinfo(*av, NULL, NULL, &res)) + errx(EX_DATAERR, NULL); + /* Just use the first host in the answer. */ + family = res->ai_family; + memcpy(&result, res->ai_addr, res->ai_addrlen); + freeaddrinfo(res); + if (family == PF_INET) { ipfw_insn_sa *p = (ipfw_insn_sa *)action;