summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bpf.c2
-rw-r--r--bpf_comp.c2
-rw-r--r--netsniff-ng.c2
-rw-r--r--trafgen_parser.y26
-rw-r--r--xmalloc.c13
-rw-r--r--xmalloc.h2
6 files changed, 22 insertions, 25 deletions
diff --git a/bpf.c b/bpf.c
index 6239af9..25cf25d 100644
--- a/bpf.c
+++ b/bpf.c
@@ -755,7 +755,7 @@ void bpf_parse_rules(char *rulefile, struct sock_fprog *bpf, uint32_t link_type)
panic("BPF syntax error!\n");
bpf->len++;
- bpf->filter = xrealloc(bpf->filter, 1,
+ bpf->filter = xrealloc(bpf->filter,
bpf->len * sizeof(sf_single));
fmemcpy(&bpf->filter[bpf->len - 1], &sf_single,
diff --git a/bpf_comp.c b/bpf_comp.c
index 8298289..3434daf 100644
--- a/bpf_comp.c
+++ b/bpf_comp.c
@@ -24,7 +24,7 @@ void bpf_try_compile(const char *rulefile, struct sock_fprog *bpf, uint32_t link
panic("Cannot compile filter %s\n", rulefile);
bpf->len = _bpf.bf_len;
- bpf->filter = xrealloc(bpf->filter, 1, bpf->len * sizeof(*out));
+ bpf->filter = xrealloc(bpf->filter, bpf->len * sizeof(*out));
for (i = 0, ins = _bpf.bf_insns, out = bpf->filter; i < bpf->len;
++i, ++ins, ++out) {
diff --git a/netsniff-ng.c b/netsniff-ng.c
index 5477257..a2067d3 100644
--- a/netsniff-ng.c
+++ b/netsniff-ng.c
@@ -1400,7 +1400,7 @@ int main(int argc, char **argv)
size_t alen = strlen(argv[i]) + 2;
size_t flen = ctx.filter ? strlen(ctx.filter) : 0;
- ctx.filter = xrealloc(ctx.filter, 1, flen + alen);
+ ctx.filter = xrealloc(ctx.filter, flen + alen);
ret = slprintf(ctx.filter + offset, strlen(argv[i]) + 2, "%s ", argv[i]);
if (ret < 0)
panic("Cannot concatenate filter string!\n");
diff --git a/trafgen_parser.y b/trafgen_parser.y
index ef753da..ee3d476 100644
--- a/trafgen_parser.y
+++ b/trafgen_parser.y
@@ -127,12 +127,12 @@ static void realloc_packet(void)
return;
plen++;
- packets = xrealloc(packets, 1, plen * sizeof(*packets));
+ packets = xrealloc(packets, plen * sizeof(*packets));
__init_new_packet_slot(&packets[packet_last]);
dlen++;
- packet_dyn = xrealloc(packet_dyn, 1, dlen * sizeof(*packet_dyn));
+ packet_dyn = xrealloc(packet_dyn, dlen * sizeof(*packet_dyn));
__init_new_counter_slot(&packet_dyn[packetd_last]);
__init_new_randomizer_slot(&packet_dyn[packetd_last]);
@@ -147,7 +147,7 @@ static void set_byte(uint8_t val)
return;
pkt->len++;
- pkt->payload = xrealloc(pkt->payload, 1, pkt->len);
+ pkt->payload = xrealloc(pkt->payload, pkt->len);
pkt->payload[payload_last] = val;
}
@@ -168,7 +168,7 @@ static void set_fill(uint8_t val, size_t len)
return;
pkt->len += len;
- pkt->payload = xrealloc(pkt->payload, 1, pkt->len);
+ pkt->payload = xrealloc(pkt->payload, pkt->len);
for (i = 0; i < len; ++i)
pkt->payload[payload_last - i] = val;
}
@@ -179,10 +179,10 @@ static void __set_csum16_dynamic(size_t from, size_t to, enum csum which)
struct packet_dyn *pktd = &packet_dyn[packetd_last];
pkt->len += 2;
- pkt->payload = xrealloc(pkt->payload, 1, pkt->len);
+ pkt->payload = xrealloc(pkt->payload, pkt->len);
pktd->slen++;
- pktd->csum = xrealloc(pktd->csum, 1, pktd->slen * sizeof(struct csum16));
+ pktd->csum = xrealloc(pktd->csum, pktd->slen * sizeof(struct csum16));
__setup_new_csum16(&pktd->csum[packetds_last], from, to, which);
}
@@ -236,7 +236,7 @@ static void set_rnd(size_t len)
return;
pkt->len += len;
- pkt->payload = xrealloc(pkt->payload, 1, pkt->len);
+ pkt->payload = xrealloc(pkt->payload, pkt->len);
for (i = 0; i < len; ++i)
pkt->payload[payload_last - i] = (uint8_t) rand();
}
@@ -250,7 +250,7 @@ static void set_sequential_inc(uint8_t start, size_t len, uint8_t stepping)
return;
pkt->len += len;
- pkt->payload = xrealloc(pkt->payload, 1, pkt->len);
+ pkt->payload = xrealloc(pkt->payload, pkt->len);
for (i = 0; i < len; ++i) {
off_t off = len - 1 - i;
@@ -268,7 +268,7 @@ static void set_sequential_dec(uint8_t start, size_t len, uint8_t stepping)
return;
pkt->len += len;
- pkt->payload = xrealloc(pkt->payload, 1, pkt->len);
+ pkt->payload = xrealloc(pkt->payload, pkt->len);
for (i = 0; i < len; ++i) {
int off = len - 1 - i;
@@ -286,10 +286,10 @@ static void set_dynamic_rnd(void)
return;
pkt->len++;
- pkt->payload = xrealloc(pkt->payload, 1, pkt->len);
+ pkt->payload = xrealloc(pkt->payload, pkt->len);
pktd->rlen++;
- pktd->rnd = xrealloc(pktd->rnd, 1, pktd->rlen * sizeof(struct randomizer));
+ pktd->rnd = xrealloc(pktd->rnd, pktd->rlen * sizeof(struct randomizer));
__setup_new_randomizer(&pktd->rnd[packetdr_last]);
}
@@ -304,10 +304,10 @@ static void set_dynamic_incdec(uint8_t start, uint8_t stop, uint8_t stepping,
return;
pkt->len++;
- pkt->payload = xrealloc(pkt->payload, 1, pkt->len);
+ pkt->payload = xrealloc(pkt->payload, pkt->len);
pktd->clen++;
- pktd->cnt =xrealloc(pktd->cnt, 1, pktd->clen * sizeof(struct counter));
+ pktd->cnt = xrealloc(pktd->cnt, pktd->clen * sizeof(struct counter));
__setup_new_counter(&pktd->cnt[packetdc_last], start, stop, stepping, type);
}
diff --git a/xmalloc.c b/xmalloc.c
index 18972fb..75319ff 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -1,6 +1,7 @@
/*
* netsniff-ng - the packet sniffing beast
* Copyright 2009, 2010, 2011, 2012 Daniel Borkmann.
+ * Copyright 2014, 2015 Tobias Klauser
* Subject to the GPL, version 2.
*/
@@ -98,20 +99,16 @@ void *xmemdupz(const void *data, size_t len)
return memcpy(xmallocz(len), data, len);
}
-void *xrealloc(void *ptr, size_t nmemb, size_t size)
+void *xrealloc(void *ptr, size_t size)
{
void *new_ptr;
- size_t new_size = nmemb * size;
- if (unlikely(new_size == 0))
+ if (unlikely(size == 0))
panic("xrealloc: zero size\n");
- if (unlikely(((size_t) ~0) / nmemb < size))
- panic("xrealloc: nmemb * size > SIZE_T_MAX\n");
- new_ptr = realloc(ptr, new_size);
+ new_ptr = realloc(ptr, size);
if (unlikely(new_ptr == NULL))
- panic("xrealloc: out of memory (new_size %zu bytes)\n",
- new_size);
+ panic("xrealloc: out of memory (allocating %zu bytes)\n", size);
return new_ptr;
}
diff --git a/xmalloc.h b/xmalloc.h
index 2ad0372..5d96f48 100644
--- a/xmalloc.h
+++ b/xmalloc.h
@@ -13,7 +13,7 @@ extern void *xmallocz(size_t size) __hidden;
extern void *xmalloc_aligned(size_t size, size_t alignment) __hidden;
extern void *xzmalloc_aligned(size_t size, size_t alignment) __hidden;
extern void *xmemdupz(const void *data, size_t len) __hidden;
-extern void *xrealloc(void *ptr, size_t nmemb, size_t size) __hidden;
+extern void *xrealloc(void *ptr, size_t size) __hidden;
extern void xfree_func(void *ptr) __hidden;
extern char *xstrdup(const char *str) __hidden;
extern char *xstrndup(const char *str, size_t size) __hidden;