git: a451bdf25b53 - main - pfctl: clean up TAILQ use in symset()/symget()

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Fri, 09 May 2025 22:16:19 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=a451bdf25b534130d7ec5a6e3ef8e7b33fc6bdd5

commit a451bdf25b534130d7ec5a6e3ef8e7b33fc6bdd5
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2025-05-08 15:14:18 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2025-05-09 20:49:29 +0000

    pfctl: clean up TAILQ use in symset()/symget()
    
    Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
    with more modern TAILQ_FOREACH(). This what symget() was already
    doing.
    
    Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().
    
    No intentional functional change.
    
    ok bluhm@ otto@
    
    Obtained from:  OpenBSD, krw <krw@openbsd.org>, 54c95b7a05
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 sbin/pfctl/parse.y | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y
index f1ed5444cadd..befa5a9b0d39 100644
--- a/sbin/pfctl/parse.y
+++ b/sbin/pfctl/parse.y
@@ -7178,9 +7178,10 @@ symset(const char *nam, const char *val, int persist)
 {
 	struct sym	*sym;
 
-	for (sym = TAILQ_FIRST(&symhead); sym && strcmp(nam, sym->nam);
-	    sym = TAILQ_NEXT(sym, entry))
-		;	/* nothing */
+	TAILQ_FOREACH(sym, &symhead, entry) {
+		if (strcmp(nam, sym->nam) == 0)
+			break;
+	}
 
 	if (sym != NULL) {
 		if (sym->persist == 1)
@@ -7237,11 +7238,12 @@ symget(const char *nam)
 {
 	struct sym	*sym;
 
-	TAILQ_FOREACH(sym, &symhead, entry)
+	TAILQ_FOREACH(sym, &symhead, entry) {
 		if (strcmp(nam, sym->nam) == 0) {
 			sym->used = 1;
 			return (sym->val);
 		}
+	}
 	return (NULL);
 }