summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2014-10-16 20:08:22 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2014-10-16 20:08:22 +0000
commitddb93a7655bdfdf840906b572520b44fb2c913e7 (patch)
treeaa9ec86bc92546913716b864bd5e8d300f836099
parentaabbe96548ee8131cd29f5761c59046dc442e0d2 (diff)
use reallocarray(); ok lteo
-rw-r--r--lib/libpcap/pcap-bpf.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/libpcap/pcap-bpf.c b/lib/libpcap/pcap-bpf.c
index 758572d7cf2..12a7130e3aa 100644
--- a/lib/libpcap/pcap-bpf.c
+++ b/lib/libpcap/pcap-bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcap-bpf.c,v 1.23 2014/03/14 03:44:13 lteo Exp $ */
+/* $OpenBSD: pcap-bpf.c,v 1.24 2014/10/16 20:08:21 deraadt Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1998
@@ -972,7 +972,6 @@ fail:
int
pcap_setfilter(pcap_t *p, struct bpf_program *fp)
{
- size_t buflen;
/*
* It looks that BPF code generated by gen_protochain() is not
* compatible with some of kernel BPF code (for example BSD/OS 3.1).
@@ -981,15 +980,16 @@ pcap_setfilter(pcap_t *p, struct bpf_program *fp)
if (no_optimize || (p->sf.rfile != NULL)){
if (p->fcode.bf_insns != NULL)
pcap_freecode(&p->fcode);
- buflen = sizeof(*fp->bf_insns) * fp->bf_len;
p->fcode.bf_len = fp->bf_len;
- p->fcode.bf_insns = malloc(buflen);
+ p->fcode.bf_insns = reallocarray(NULL,
+ fp->bf_len, sizeof(*fp->bf_insns));
if (p->fcode.bf_insns == NULL) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "malloc: %s",
pcap_strerror(errno));
return (-1);
}
- memcpy(p->fcode.bf_insns, fp->bf_insns, buflen);
+ memcpy(p->fcode.bf_insns, fp->bf_insns,
+ fp->bf_len * sizeof(*fp->bf_insns));
} else if (ioctl(p->fd, BIOCSETF, (caddr_t)fp) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSETF: %s",
pcap_strerror(errno));