summaryrefslogtreecommitdiff
path: root/ring_tx.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2014-04-30 13:32:08 +0200
committerTobias Klauser <tklauser@distanz.ch>2014-04-30 13:32:08 +0200
commitf4821f92614bafaaee01721b3a5ffc29fe2f5365 (patch)
tree87b71ab410183ad1497e7cf6798aa7b3dc72dba3 /ring_tx.c
parent190dc7879a1a8813f2332ee7b39b743a49ac2771 (diff)
ring: Consistently use size_t to specify ring size
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 <jonschipp@gmail.com> Reported-by: Michał Purzyński <michalpurzynski1@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'ring_tx.c')
-rw-r--r--ring_tx.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/ring_tx.c b/ring_tx.c
index 17d5f26..ee47f3f 100644
--- a/ring_tx.c
+++ b/ring_tx.c
@@ -45,7 +45,7 @@ void destroy_tx_ring(int sock, struct ring *ring)
xfree(ring->frames);
}
-void setup_tx_ring_layout(int sock, struct ring *ring, unsigned int size,
+void setup_tx_ring_layout(int sock, struct ring *ring, size_t size,
bool jumbo_support)
{
fmemset(&ring->layout, 0, sizeof(ring->layout));
@@ -86,7 +86,7 @@ retry:
if (ret < 0)
panic("Cannot allocate TX_RING!\n");
- ring->mm_len = ring->layout.tp_block_size * ring->layout.tp_block_nr;
+ ring->mm_len = (size_t) ring->layout.tp_block_size * ring->layout.tp_block_nr;
if (verbose) {
printf("TX,V2: %.2Lf MiB, %u Frames, each %u Byte allocated\n",