diff options
author | Jared Yanovich <jaredy@cvs.openbsd.org> | 2006-01-11 07:31:47 +0000 |
---|---|---|
committer | Jared Yanovich <jaredy@cvs.openbsd.org> | 2006-01-11 07:31:47 +0000 |
commit | 5f4f2d57f837958fdbeb3ff3f376c3337b35f7c9 (patch) | |
tree | c15123ec59fbb775eccf8cadf0d127f9f94c7f61 /lib/libpcap/pcap-bpf.c | |
parent | 198e5b842cc7100e4ee97dd33dda1f51aa0d2453 (diff) |
- check for malloc failure
- plug some memleaks
- avoid close(-1) when open() fails in pcap_open_live()
sent upstream where applicable
ok djm moritz
Diffstat (limited to 'lib/libpcap/pcap-bpf.c')
-rw-r--r-- | lib/libpcap/pcap-bpf.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/libpcap/pcap-bpf.c b/lib/libpcap/pcap-bpf.c index ac72b43f703..6a9ef0c885b 100644 --- a/lib/libpcap/pcap-bpf.c +++ b/lib/libpcap/pcap-bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pcap-bpf.c,v 1.17 2005/11/18 11:05:39 djm Exp $ */ +/* $OpenBSD: pcap-bpf.c,v 1.18 2006/01/11 07:31:46 jaredy Exp $ */ /* * Copyright (c) 1993, 1994, 1995, 1996, 1998 @@ -107,7 +107,7 @@ pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) (void)lseek(p->fd, 0L, SEEK_SET); goto again; } - /* fall through */ + /* FALLTHROUGH */ #endif } snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "read: %s", @@ -208,6 +208,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms, pcap_t *p; struct bpf_dltlist bdl; + bzero(&bdl, sizeof(bdl)); p = (pcap_t *)malloc(sizeof(*p)); if (p == NULL) { snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s", @@ -276,7 +277,6 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms, * this interface supports. If this fails with EINVAL, it's * not fatal; we just don't get to use the feature later. */ - bzero(&bdl, sizeof(bdl)); if (ioctl(fd, BIOCGDLTLIST, (caddr_t)&bdl) == 0) { bdl.bfl_list = (u_int *) malloc(sizeof(u_int) * bdl.bfl_len + 1); @@ -289,7 +289,6 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms, if (ioctl(fd, BIOCGDLTLIST, (caddr_t)&bdl) < 0) { (void)snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCGDLTLIST: %s", pcap_strerror(errno)); - free(bdl.bfl_list); goto bad; } p->dlt_count = bdl.bfl_len; @@ -332,7 +331,9 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms, return (p); bad: - (void)close(fd); + if (fd >= 0) + (void)close(fd); + free(bdl.bfl_list); free(p); return (NULL); } |