The branch main has been updated by kp:

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

commit 7b82e362036763498734ec6ceb74f512c2c05d81
Author:     Kristof Provost <k...@freebsd.org>
AuthorDate: 2025-06-27 09:48:22 +0000
Commit:     Kristof Provost <k...@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 <k...@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)

Reply via email to