git: 5b7bfd0046c2 - main - pfctl: consolidate some code by using reallocarray in all cases
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 19 Feb 2025 10:41:39 UTC
The branch main has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=5b7bfd0046c2a3725fa71783ac7d7b842ec0de58
commit 5b7bfd0046c2a3725fa71783ac7d7b842ec0de58
Author: Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2025-02-11 15:12:55 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2025-02-19 10:41:09 +0000
pfctl: consolidate some code by using reallocarray in all cases
ok deraadt millert
Obtained from: OpenBSD, tedu <tedu@openbsd.org>, 97d14fe110
Sponsored by: Rubicon Communications, LLC ("Netgate")
---
sbin/pfctl/pfctl_radix.c | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)
diff --git a/sbin/pfctl/pfctl_radix.c b/sbin/pfctl/pfctl_radix.c
index 94de63414885..3bb2469a9bfb 100644
--- a/sbin/pfctl/pfctl_radix.c
+++ b/sbin/pfctl/pfctl_radix.c
@@ -434,25 +434,15 @@ pfr_buf_grow(struct pfr_buffer *b, int minsize)
if (!b->pfrb_msize) {
if (minsize < 64)
minsize = 64;
- b->pfrb_caddr = calloc(bs, minsize);
- if (b->pfrb_caddr == NULL)
- return (-1);
- b->pfrb_msize = minsize;
- } else {
- if (minsize == 0)
- minsize = b->pfrb_msize * 2;
- if (minsize < 0 || minsize >= SIZE_T_MAX / bs) {
- /* msize overflow */
- errno = ENOMEM;
- return (-1);
- }
- p = realloc(b->pfrb_caddr, minsize * bs);
- if (p == NULL)
- return (-1);
- bzero(p + b->pfrb_msize * bs, (minsize - b->pfrb_msize) * bs);
- b->pfrb_caddr = p;
- b->pfrb_msize = minsize;
}
+ if (minsize == 0)
+ minsize = b->pfrb_msize * 2;
+ p = reallocarray(b->pfrb_caddr, minsize, bs);
+ if (p == NULL)
+ return (-1);
+ bzero(p + b->pfrb_msize * bs, (minsize - b->pfrb_msize) * bs);
+ b->pfrb_caddr = p;
+ b->pfrb_msize = minsize;
return (0);
}