From 5e46e06624305fff92f0f2eaa2809270fd7c5361 Mon Sep 17 00:00:00 2001 From: Cedric Berger Date: Tue, 4 Feb 2003 17:29:07 +0000 Subject: use size_t for struct size and offset calculations. check msize for overflow and realloc overflow. --- sbin/pfctl/pfctl_table.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'sbin/pfctl') diff --git a/sbin/pfctl/pfctl_table.c b/sbin/pfctl/pfctl_table.c index 41d0a4008b7..199a6034ce4 100644 --- a/sbin/pfctl/pfctl_table.c +++ b/sbin/pfctl/pfctl_table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl_table.c,v 1.32 2003/02/04 12:10:02 cedric Exp $ */ +/* $OpenBSD: pfctl_table.c,v 1.33 2003/02/04 17:29:06 cedric Exp $ */ /* * Copyright (c) 2002 Cedric Berger @@ -56,7 +56,7 @@ extern void usage(void); static int pfctl_table(int, char *[], char *, char *, char *, int); -static void grow_buffer(int, int); +static void grow_buffer(size_t, int); static void print_table(struct pfr_table *, int); static void print_tstats(struct pfr_tstats *, int); static void load_addr(int, char *[], char *, int); @@ -310,7 +310,7 @@ pfctl_table(int argc, char *argv[], char *tname, char *command, } void -grow_buffer(int bs, int minsize) +grow_buffer(size_t bs, int minsize) { assert(minsize == 0 || minsize > msize); if (!msize) { @@ -326,6 +326,8 @@ grow_buffer(int bs, int minsize) msize *= 2; else msize = minsize; + if (msize < 0 || msize >= SIZE_T_MAX / bs) + err(1, "buffer overflow"); buffer.caddr = realloc(buffer.caddr, msize * bs); if (buffer.caddr == NULL) err(1, "realloc"); -- cgit v1.2.3