From nobody Mon Jul 7 15:07:56 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bbSKT2t4Bz61w2w; Mon, 07 Jul 2025 15:07:57 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bbSKT10rpz3wRD; Mon, 07 Jul 2025 15:07:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1751900877; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Z5bWVioByw1YT4oHJkU0BxiqCnbFKg3G5hanlGCh0uI=; b=sC0RGJboGrR71ZeeF5MglwTws8c52bUqU8JtIv0uyPtSrv0AlFx9F9yIFlWwHK1gkjehF7 dT0KUF6JcUyKWaBrQxR+yafosp4Rrz/GYZXB5FAcH36YA/PwBPNz0nt964iO4BUnS+NM7A v3s8gR9aL2jUj9D+XfOk27TeGXoHL2e+9yUUNf/mhqcQqem1Pv2jIVYbc9foEH+OSFheDR R3xfAHwMSTED2uX5W2io3/MbutN0RK7oUvJqGLiJ+6jPmEbCT0edUJKNycEs2+HT5mRIFt EdU9GutRnCEu0ChpVieIeiM99+VSZrXg72KRFCTDTIY8U0S6xqIm6sRXKnB75A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1751900877; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Z5bWVioByw1YT4oHJkU0BxiqCnbFKg3G5hanlGCh0uI=; b=btt5pgMREkYAZ+qyZHToug9umKPy8/AFKRLL/kcC+23PGf0XPQ1Sh2jsP9udCPEJm8zx9Y EkZ/ShWmr/WqzSZPpD+GFhIf/aTnW6CovXmeV8Miy/QFN9prxHN36VTO/ABy9bkN538Lqv /pfRoBRTwkNQcRiyj8XpnapqZsUuIQxDtqiRG5JnqHwPUOD8FWtvxMS7PNcFLtbqfUivEK X/XMrHk+caDEpitjWEUgp+f+MlZ7Af6BJJnaCufdyhyes7YiLrZpyu7meSqpqt0Qup0o3d zF0XgRVgZo9r9dWYlAycYnPyAKVEt7gy3lmJ+XARZjxOEuTaX/1GR0FFEPD1bA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1751900877; a=rsa-sha256; cv=none; b=VQ0q8C8dj4tx8ognvcZYl9Rclie9CFUq0qiS8sz8UCMl7hRfeHBEx06GTQWc1htmpCShGb 8MEZIttLFfS0EydbPKEoz9yvJwbSNi1lnPuXTgR8J/L1OTjuWCZdST+ZZwBAKvUn7/KE1j bClcZjaJuMT794gYGDL7JNEwlIwE5hRhi8sl5VFH/Uf5qjKuRZzPqRX3S3w6ixvje2/TRN tk4SBN7anpcS7TCLBloGjDy6gw5qHgrwsOcs1ENa8HdDDz1SE0T20CcsWZ4aq/c0QWl3GB aYWwNOd7Z3JydEu29eqGhKLpKUAHspwsY+UAiDRu/lxBEfbynwjssUrS3LyDCQ== 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 4bbSKT0ZxqzwF4; Mon, 07 Jul 2025 15:07:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 567F7usL016662; Mon, 7 Jul 2025 15:07:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 567F7uri016659; Mon, 7 Jul 2025 15:07:56 GMT (envelope-from git) Date: Mon, 7 Jul 2025 15:07:56 GMT Message-Id: <202507071507.567F7uri016659@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 7ea14ad4db6b - main - pfctl: Unify anchor name sanity checks List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7ea14ad4db6bd840c05eaa8b4ebb941c983a9424 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=7ea14ad4db6bd840c05eaa8b4ebb941c983a9424 commit 7ea14ad4db6bd840c05eaa8b4ebb941c983a9424 Author: Kristof Provost AuthorDate: 2025-07-02 12:46:51 +0000 Commit: Kristof Provost CommitDate: 2025-07-07 15:06:50 +0000 pfctl: Unify anchor name sanity checks For anchor names, make `load anchor' use the same grammar as `anchor' and merge unique checks from both places so that anchor names are validated regardless of the specific rule at hand. OK sashan Obtained from: OpenBSD, kn , 0f06db3497 Sponsored by: Rubicon Communications, LLC ("Netgate") --- sbin/pfctl/parse.y | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y index 0b98bd357a37..2ebd528443fe 100644 --- a/sbin/pfctl/parse.y +++ b/sbin/pfctl/parse.y @@ -921,7 +921,22 @@ varset : STRING '=' varstring { } ; -anchorname : STRING { $$ = $1; } +anchorname : STRING { + if (strlen(pf->anchor->path) + 1 + + strlen($1) >= PATH_MAX) { + free($1); + yyerror("anchor name is longer than %u", + PATH_MAX - 1); + YYERROR; + } + if ($1[0] == '_' || strstr($1, "/_") != NULL) { + free($1); + yyerror("anchor names beginning with '_' " + "are reserved for internal use"); + YYERROR; + } + $$ = $1; + } | /* empty */ { $$ = NULL; } ; @@ -974,13 +989,6 @@ anchorrule : ANCHOR anchorname dir quick interface af proto fromto YYERROR; } - if ($2 && ($2[0] == '_' || strstr($2, "/_") != NULL)) { - free($2); - yyerror("anchor names beginning with '_' " - "are reserved for internal use"); - YYERROR; - } - pfctl_init_rule(&r); if (pf->astack[pf->asd + 1]) { @@ -1162,14 +1170,11 @@ anchorrule : ANCHOR anchorname dir quick interface af proto fromto } ; -loadrule : LOAD ANCHOR string FROM string { +loadrule : LOAD ANCHOR anchorname FROM string { struct loadanchors *loadanchor; - if (strlen(pf->anchor->path) + 1 + - strlen($3) >= MAXPATHLEN) { - yyerror("anchorname %s too long, max %u\n", - $3, MAXPATHLEN - 1); - free($3); + if ($3 == NULL) { + yyerror("anchor name is missing"); YYERROR; } loadanchor = calloc(1, sizeof(struct loadanchors));