Date: Mon, 30 Jun 2025 15:00:50 GMT From: Kristof Provost <kp@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 7b82e3620367 - main - pfctl: Use strtonum in host() Message-ID: <202506301500.55UF0ox1047505@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=7b82e362036763498734ec6ceb74f512c2c05d81 commit 7b82e362036763498734ec6ceb74f512c2c05d81 Author: Kristof Provost <kp@FreeBSD.org> AuthorDate: 2025-06-27 09:48:22 +0000 Commit: Kristof Provost <kp@FreeBSD.org> CommitDate: 2025-06-30 15:00:27 +0000 pfctl: Use strtonum in host() This is simpler than checking three cases for `q' and gives nicer error messages. While here, use `v6mask' as maximum netmask instead of hardcoding it. OK sashan Obtained from: OpenBSD, kn <kn@openbsd.org>, e351e6cba3 Sponsored by: Rubicon Communications, LLC ("Netgate") --- sbin/pfctl/pfctl_parser.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sbin/pfctl/pfctl_parser.c b/sbin/pfctl/pfctl_parser.c index 89960efa3ca1..71731652e4af 100644 --- a/sbin/pfctl/pfctl_parser.c +++ b/sbin/pfctl/pfctl_parser.c @@ -1803,13 +1803,14 @@ struct node_host * host(const char *s, int opts) { struct node_host *h = NULL; - int mask, v4mask, v6mask, cont = 1; - char *p, *q, *ps; + int mask, v4mask, v6mask = 128, cont = 1; + char *p, *ps; + const char *errstr; if ((p = strrchr(s, '/')) != NULL) { - mask = strtol(p+1, &q, 0); - if (!q || *q || mask > 128 || q == (p+1)) { - fprintf(stderr, "invalid netmask '%s'\n", p); + mask = strtonum(p+1, 0, v6mask, &errstr); + if (errstr) { + fprintf(stderr, "netmask is %s: %s\n", errstr, p); return (NULL); } if ((ps = malloc(strlen(s) - strlen(p) + 1)) == NULL)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202506301500.55UF0ox1047505>