From f4821f92614bafaaee01721b3a5ffc29fe2f5365 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 30 Apr 2014 13:32:08 +0200 Subject: ring: Consistently use size_t to specify ring size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The mm_len member of struct ring is of type size_t, but in the code paths leading to set it, unsigned int is used. In circumstances where unsigned int is 32 bit and size_t is 64 bit, this could lead to an integer overflow, which causes an improper ring size being mmap()'ed in mmap_ring_generic(). In order to prevent this, consistently use size_t to store the ring size, since this is also what mmap() takes as its `length' parameter. This now allows to specify ring sizes larger than 4 GiB for both netsniff-ng and trafgen (fixes #90). Reported-by: Jon Schipp Reported-by: Michał Purzyński Signed-off-by: Tobias Klauser --- trafgen.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'trafgen.c') diff --git a/trafgen.c b/trafgen.c index 489ff53..43148b7 100644 --- a/trafgen.c +++ b/trafgen.c @@ -56,7 +56,8 @@ struct ctx { bool rand, rfraw, jumbo_support, verbose, smoke_test, enforce, qdisc_path; - unsigned long num, reserve_size; + size_t reserve_size; + unsigned long num; unsigned int cpus; uid_t uid; gid_t gid; char *device, *device_trans, *rhost; @@ -590,7 +591,8 @@ static void xmit_fastpath_or_die(struct ctx *ctx, int cpu, unsigned long orig_nu int ifindex = device_ifindex(ctx->device); uint8_t *out = NULL; unsigned int it = 0; - unsigned long num = 1, i = 0, size; + unsigned long num = 1, i = 0; + size_t size; struct ring tx_ring; struct frame_map *hdr; struct timeval start, end, diff; -- cgit v1.2.3-54-g00ecf