Skip to content

Commit

Permalink
Merge pull request #414 from peugnezb/correctifs
Browse files Browse the repository at this point in the history
Bug fixes to gencode.c/gencode.h and pcap-linux.c

If tp version is not valid, we don't do anything in the switch, and thus don't set req.tp_frame_nr, but we later use it.  (This "shouldn't happen", as we should never use a TPACKET_ version we don't handle, but this catches that case in case it can happen.)

The variable "len" needs to be initialized to the buffer size "&bpf_extensions" - it's a value-result parameter in getsockopt(), which should be set to the size of the buffer being passed.

Make the mask length parameter in some gencode.c routines unsigned.

Close a socket file descriptor in the right place.
  • Loading branch information
guyharris committed Feb 3, 2015
2 parents 4786f88 + 23406ae commit e598f98
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions gencode.c
Expand Up @@ -6525,7 +6525,7 @@ gen_scode(name, q)
struct block *
gen_mcode(s1, s2, masklen, q)
register const char *s1, *s2;
register int masklen;
register unsigned int masklen;
struct qual q;
{
register int nlen, mlen;
Expand Down Expand Up @@ -6684,7 +6684,7 @@ gen_ncode(s, v, q)
struct block *
gen_mcode6(s1, s2, masklen, q)
register const char *s1, *s2;
register int masklen;
register unsigned int masklen;
struct qual q;
{
struct addrinfo *res;
Expand Down
4 changes: 2 additions & 2 deletions gencode.h
Expand Up @@ -294,9 +294,9 @@ void gen_not(struct block *);
struct block *gen_scode(const char *, struct qual);
struct block *gen_ecode(const u_char *, struct qual);
struct block *gen_acode(const u_char *, struct qual);
struct block *gen_mcode(const char *, const char *, int, struct qual);
struct block *gen_mcode(const char *, const char *, unsigned int, struct qual);
#ifdef INET6
struct block *gen_mcode6(const char *, const char *, int, struct qual);
struct block *gen_mcode6(const char *, const char *, unsigned int, struct qual);
#endif
struct block *gen_ncode(const char *, bpf_u_int32, struct qual);
struct block *gen_proto_abbrev(int);
Expand Down
10 changes: 8 additions & 2 deletions pcap-linux.c
Expand Up @@ -3017,7 +3017,7 @@ activate_new(pcap_t *handle)
struct packet_mreq mr;
#ifdef SO_BPF_EXTENSIONS
int bpf_extensions;
socklen_t len;
socklen_t len = sizeof(bpf_extensions);
#endif

/*
Expand Down Expand Up @@ -3758,6 +3758,12 @@ create_ring(pcap_t *handle, int *status)
req.tp_frame_nr = handle->opt.buffer_size/req.tp_frame_size;
break;
#endif
default:
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Internal error: unknown TPACKET_value %d",
handlep->tp_version);
*status = PCAP_ERROR;
return -1;
}

/* compute the minumum block size that will handle this frame.
Expand Down Expand Up @@ -5541,6 +5547,7 @@ iface_ethtool_get_ts_info(pcap_t *handle, char *ebuf)
info.cmd = ETHTOOL_GET_TS_INFO;
ifr.ifr_data = (caddr_t)&info;
if (ioctl(fd, SIOCETHTOOL, &ifr) == -1) {
close(fd);
if (errno == EOPNOTSUPP || errno == EINVAL) {
/*
* OK, let's just return all the possible time
Expand All @@ -5552,7 +5559,6 @@ iface_ethtool_get_ts_info(pcap_t *handle, char *ebuf)
snprintf(ebuf, PCAP_ERRBUF_SIZE,
"%s: SIOCETHTOOL(ETHTOOL_GET_TS_INFO) ioctl failed: %s", handle->opt.source,
strerror(errno));
close(fd);
return -1;
}
close(fd);
Expand Down

0 comments on commit e598f98

Please sign in to comment.