diff options
-rw-r--r-- | diag-control.h | 27 | ||||
-rw-r--r-- | pcap-bpf.c | 20 | ||||
-rw-r--r-- | pcap-bt-linux.c | 6 | ||||
-rw-r--r-- | pcap-bt-monitor-linux.c | 4 | ||||
-rw-r--r-- | pcap-dag.c | 2 | ||||
-rw-r--r-- | pcap-dbus.c | 2 | ||||
-rw-r--r-- | pcap-dlpi.c | 2 | ||||
-rw-r--r-- | pcap-int.h | 2 | ||||
-rw-r--r-- | pcap-libdlpi.c | 4 | ||||
-rw-r--r-- | pcap-linux.c | 39 | ||||
-rw-r--r-- | pcap-netfilter-linux.c | 16 | ||||
-rw-r--r-- | pcap-netmap.c | 2 | ||||
-rw-r--r-- | pcap-nit.c | 2 | ||||
-rw-r--r-- | pcap-npf.c | 4 | ||||
-rw-r--r-- | pcap-pf.c | 2 | ||||
-rw-r--r-- | pcap-rdmasniff.c | 2 | ||||
-rw-r--r-- | pcap-septel.c | 2 | ||||
-rw-r--r-- | pcap-sita.c | 2 | ||||
-rw-r--r-- | pcap-snf.c | 2 | ||||
-rw-r--r-- | pcap-snit.c | 2 | ||||
-rw-r--r-- | pcap-snoop.c | 2 | ||||
-rw-r--r-- | pcap-usb-linux.c | 25 | ||||
-rw-r--r-- | pcap.c | 26 | ||||
-rw-r--r-- | savefile.c | 2 | ||||
-rw-r--r-- | sf-pcap.c | 2 |
25 files changed, 128 insertions, 73 deletions
diff --git a/diag-control.h b/diag-control.h index cfc581b3..f710c6c1 100644 --- a/diag-control.h +++ b/diag-control.h @@ -65,6 +65,14 @@ __pragma(warning(disable:4244)) \ __pragma(warning(disable:4702)) #define DIAG_ON_FLEX __pragma(warning(pop)) + + /* + * Suppress narrowing warnings. + */ + #define DIAG_OFF_NARROWING \ + __pragma(warning(push)) \ + __pragma(warning(disable:4242)) + #define DIAG_ON_NARROWING __pragma(warning(pop)) #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8) /* * This is Clang 2.8 or later; we can use "clang diagnostic @@ -79,11 +87,22 @@ PCAP_DO_PRAGMA(clang diagnostic push) \ PCAP_DO_PRAGMA(clang diagnostic ignored "-Wsign-compare") \ PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation") \ + PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshorten-64-to-32") \ PCAP_DO_PRAGMA(clang diagnostic ignored "-Wmissing-noreturn") \ PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunused-parameter") \ PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code") #define DIAG_ON_FLEX \ PCAP_DO_PRAGMA(clang diagnostic pop) + + /* + * Suppress the only narrowing warnings you get from Clang. + */ + #define DIAG_OFF_NARROWING \ + PCAP_DO_PRAGMA(clang diagnostic push) \ + PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshorten-64-to-32") + + #define DIAG_ON_NARROWING \ + PCAP_DO_PRAGMA(clang diagnostic pop) #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6) /* * This is GCC 4.6 or later, or a compiler claiming to be that. @@ -97,6 +116,12 @@ PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code") #define DIAG_ON_FLEX \ PCAP_DO_PRAGMA(GCC diagnostic pop) + + /* + * GCC currently doesn't issue any narrowing warnings. + */ + #define DIAG_OFF_NARROWING + #define DIAG_ON_NARROWING #else /* * Neither Visual Studio, nor Clang 2.8 or later, nor GCC 4.6 or later @@ -105,6 +130,8 @@ */ #define DIAG_OFF_FLEX #define DIAG_ON_FLEX + #define DIAG_OFF_NARROWING + #define DIAG_ON_NARROWING #endif #ifdef YYBYACC @@ -1187,21 +1187,11 @@ pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user) } static int -pcap_inject_bpf(pcap_t *p, const void *buf, size_t size) +pcap_inject_bpf(pcap_t *p, const void *buf, int size) { - ssize_t ret; - - /* - * We return the number of bytes written, so the number of - * bytes to write must fit in an int. - */ - if (size > INT_MAX) { - pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, - errno, "More than %d bytes cannot be injected", INT_MAX); - return (PCAP_ERROR); - } + int ret; - ret = write(p->fd, buf, size); + ret = (int)write(p->fd, buf, size); #ifdef __APPLE__ if (ret == -1 && errno == EAFNOSUPPORT) { /* @@ -1233,7 +1223,7 @@ pcap_inject_bpf(pcap_t *p, const void *buf, size_t size) /* * Now try the write again. */ - ret = write(p->fd, buf, size); + ret = (int)write(p->fd, buf, size); } #endif /* __APPLE__ */ if (ret == -1) { @@ -1241,7 +1231,7 @@ pcap_inject_bpf(pcap_t *p, const void *buf, size_t size) errno, "send"); return (PCAP_ERROR); } - return ((int)ret); + return (ret); } #ifdef _AIX diff --git a/pcap-bt-linux.c b/pcap-bt-linux.c index 0c21d9c1..a0765b5b 100644 --- a/pcap-bt-linux.c +++ b/pcap-bt-linux.c @@ -58,7 +58,7 @@ /* forward declaration */ static int bt_activate(pcap_t *); static int bt_read_linux(pcap_t *, int , pcap_handler , u_char *); -static int bt_inject_linux(pcap_t *, const void *, size_t); +static int bt_inject_linux(pcap_t *, const void *, int); static int bt_setdirection_linux(pcap_t *, pcap_direction_t); static int bt_stats_linux(pcap_t *, struct pcap_stat *); @@ -346,7 +346,7 @@ bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char return -1; } - pkth.caplen = ret; + pkth.caplen = (bpf_u_int32)ret; /* get direction and timestamp*/ cmsg = CMSG_FIRSTHDR(&msg); @@ -378,7 +378,7 @@ bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char } static int -bt_inject_linux(pcap_t *handle, const void *buf _U_, size_t size _U_) +bt_inject_linux(pcap_t *handle, const void *buf _U_, int size _U_) { pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported on " "bluetooth devices"); diff --git a/pcap-bt-monitor-linux.c b/pcap-bt-monitor-linux.c index 4f127127..00d48798 100644 --- a/pcap-bt-monitor-linux.c +++ b/pcap-bt-monitor-linux.c @@ -124,7 +124,7 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch return -1; } - pkth.caplen = ret - sizeof(hdr) + sizeof(pcap_bluetooth_linux_monitor_header); + pkth.caplen = (bpf_u_int32)(ret - sizeof(hdr) + sizeof(pcap_bluetooth_linux_monitor_header)); pkth.len = pkth.caplen; for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) { @@ -147,7 +147,7 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch } static int -bt_monitor_inject(pcap_t *handle, const void *buf _U_, size_t size _U_) +bt_monitor_inject(pcap_t *handle, const void *buf _U_, int size _U_) { pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported yet"); return -1; @@ -726,7 +726,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) } static int -dag_inject(pcap_t *p, const void *buf _U_, size_t size _U_) +dag_inject(pcap_t *p, const void *buf _U_, int size _U_) { strlcpy(p->errbuf, "Sending packets isn't supported on DAG cards", PCAP_ERRBUF_SIZE); diff --git a/pcap-dbus.c b/pcap-dbus.c index 9f426e67..6b26d8ab 100644 --- a/pcap-dbus.c +++ b/pcap-dbus.c @@ -103,7 +103,7 @@ dbus_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char *us } static int -dbus_write(pcap_t *handle, const void *buf, size_t size) +dbus_write(pcap_t *handle, const void *buf, int size) { /* XXX, not tested */ struct pcap_dbus *handlep = handle->priv; diff --git a/pcap-dlpi.c b/pcap-dlpi.c index 09cb6d44..389b2ac5 100644 --- a/pcap-dlpi.c +++ b/pcap-dlpi.c @@ -247,7 +247,7 @@ pcap_read_dlpi(pcap_t *p, int cnt, pcap_handler callback, u_char *user) } static int -pcap_inject_dlpi(pcap_t *p, const void *buf, size_t size) +pcap_inject_dlpi(pcap_t *p, const void *buf, int size) { #ifdef DL_HP_RAWDLS struct pcap_dlpi *pd = p->priv; @@ -118,7 +118,7 @@ typedef int (*activate_op_t)(pcap_t *); typedef int (*can_set_rfmon_op_t)(pcap_t *); typedef int (*read_op_t)(pcap_t *, int cnt, pcap_handler, u_char *); typedef int (*next_packet_op_t)(pcap_t *, struct pcap_pkthdr *, u_char **); -typedef int (*inject_op_t)(pcap_t *, const void *, size_t); +typedef int (*inject_op_t)(pcap_t *, const void *, int); typedef void (*save_current_filter_op_t)(pcap_t *, const char *); typedef int (*setfilter_op_t)(pcap_t *, struct bpf_program *); typedef int (*setdirection_op_t)(pcap_t *, pcap_direction_t); diff --git a/pcap-libdlpi.c b/pcap-libdlpi.c index a0d16693..af167212 100644 --- a/pcap-libdlpi.c +++ b/pcap-libdlpi.c @@ -46,7 +46,7 @@ /* Forwards. */ static int dlpromiscon(pcap_t *, bpf_u_int32); static int pcap_read_libdlpi(pcap_t *, int, pcap_handler, u_char *); -static int pcap_inject_libdlpi(pcap_t *, const void *, size_t); +static int pcap_inject_libdlpi(pcap_t *, const void *, int); static void pcap_libdlpi_err(const char *, const char *, int, char *); static void pcap_cleanup_libdlpi(pcap_t *); @@ -427,7 +427,7 @@ process_pkts: } static int -pcap_inject_libdlpi(pcap_t *p, const void *buf, size_t size) +pcap_inject_libdlpi(pcap_t *p, const void *buf, int size) { struct pcap_dlpi *pd = p->priv; int retv; diff --git a/pcap-linux.c b/pcap-linux.c index 54592e66..4e4a5494 100644 --- a/pcap-linux.c +++ b/pcap-linux.c @@ -346,7 +346,7 @@ static int activate_mmap(pcap_t *, int *); static int pcap_can_set_rfmon_linux(pcap_t *); static int pcap_read_linux(pcap_t *, int, pcap_handler, u_char *); static int pcap_read_packet(pcap_t *, pcap_handler, u_char *); -static int pcap_inject_linux(pcap_t *, const void *, size_t); +static int pcap_inject_linux(pcap_t *, const void *, int); static int pcap_stats_linux(pcap_t *, struct pcap_stat *); static int pcap_setfilter_linux(pcap_t *, struct bpf_program *); static int pcap_setdirection_linux(pcap_t *, pcap_direction_t); @@ -740,7 +740,9 @@ add_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, genlmsg_put(msg, 0, 0, genl_family_get_id(state->nl80211), 0, 0, NL80211_CMD_NEW_INTERFACE, 0); NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); +DIAG_OFF_NARROWING NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, mondevice); +DIAG_ON_NARROWING NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, NL80211_IFTYPE_MONITOR); err = nl_send_auto_complete(state->nl_sock, msg); @@ -1159,7 +1161,8 @@ linux_if_drops(const char * if_name) char buffer[512]; char * bufptr; FILE * file; - int field_to_convert = 3, if_name_sz = strlen(if_name); + int field_to_convert = 3; + size_t if_name_sz = strlen(if_name); long int dropped_pkts = 0; file = fopen("/proc/net/dev", "r"); @@ -1381,7 +1384,7 @@ set_poll_timeout(struct pcap_linux *handlep) #ifdef HAVE_TPACKET3 struct utsname utsname; char *version_component, *endp; - int major, minor; + long major, minor; int broken_tpacket_v3 = 1; /* @@ -1761,7 +1764,8 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) #else /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_STRUCT_TPACKET_AUXDATA_TP_VLAN_TCI) */ socklen_t fromlen; #endif /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_STRUCT_TPACKET_AUXDATA_TP_VLAN_TCI) */ - int packet_len, caplen; + ssize_t packet_len; + int caplen; struct pcap_pkthdr pcap_header; struct bpf_aux_data aux_data; @@ -1826,8 +1830,7 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) * we were told to break out of the loop. */ handle->break_loop = 0; - return PCAP_ERROR_BREAK; - } + return PCAP_ERROR_BREA } #if defined(HAVE_PACKET_AUXDATA) && defined(HAVE_STRUCT_TPACKET_AUXDATA_TP_VLAN_TCI) packet_len = recvmsg(handle->fd, &msg, MSG_TRUNC); @@ -1947,7 +1950,7 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) if (handlep->vlan_offset != -1) { for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { struct tpacket_auxdata *aux; - unsigned int len; + size_t len; struct vlan_tag *tag; if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct tpacket_auxdata)) || @@ -1969,8 +1972,8 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) continue; } - len = (u_int)packet_len > iov.iov_len ? iov.iov_len : (u_int)packet_len; - if (len < (u_int)handlep->vlan_offset) + len = (size_t)packet_len > iov.iov_len ? iov.iov_len : (u_int)packet_len; + if (len < (size_t)handlep->vlan_offset) break; /* @@ -2128,7 +2131,7 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) } static int -pcap_inject_linux(pcap_t *handle, const void *buf, size_t size) +pcap_inject_linux(pcap_t *handle, const void *buf, int size) { struct pcap_linux *handlep = handle->priv; int ret; @@ -2162,7 +2165,7 @@ pcap_inject_linux(pcap_t *handle, const void *buf, size_t size) } #endif - ret = send(handle->fd, buf, size, 0); + ret = (int)send(handle->fd, buf, size, 0); if (ret == -1) { pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, errno, "send"); @@ -4879,7 +4882,7 @@ pcap_setnonblock_mmap(pcap_t *handle, int nonblock) /* * Get the status field of the ring buffer frame at a specified offset. */ -static inline int +static inline u_int pcap_get_ring_frame_status(pcap_t *handle, int offset) { struct pcap_linux *handlep = handle->priv; @@ -4888,10 +4891,18 @@ pcap_get_ring_frame_status(pcap_t *handle, int offset) h.raw = RING_GET_FRAME_AT(handle, offset); switch (handlep->tp_version) { case TPACKET_V1: - return (h.h1->tp_status); + /* + * This is an unsigned long, but only the lower 32 + * bits are used. + */ + return (u_int)(h.h1->tp_status); break; case TPACKET_V1_64: - return (h.h1_64->tp_status); + /* + * This is an unsigned long in the kernel, which is 64-bit, + * but only the lower 32 bits are used. + */ + return (u_int)(h.h1_64->tp_status); break; #ifdef HAVE_TPACKET2 case TPACKET_V2: diff --git a/pcap-netfilter-linux.c b/pcap-netfilter-linux.c index 675df4ae..e2cfe841 100644 --- a/pcap-netfilter-linux.c +++ b/pcap-netfilter-linux.c @@ -91,7 +91,7 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c struct pcap_netfilter *handlep = handle->priv; register u_char *bp, *ep; int count = 0; - int len; + ssize_t len; /* * Has "pcap_breakloop()" been called? @@ -152,7 +152,7 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c */ if (handle->break_loop) { handle->bp = bp; - handle->cc = ep - bp; + handle->cc = (int)(ep - bp); if (count == 0) { handle->break_loop = 0; return PCAP_ERROR_BREAK; @@ -264,12 +264,12 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c * buffer. */ if (msg_len > ep - bp) - msg_len = ep - bp; + msg_len = (uint32_t)(ep - bp); bp += msg_len; if (count >= max_packets && !PACKET_COUNT_IS_UNLIMITED(max_packets)) { handle->bp = bp; - handle->cc = ep - bp; + handle->cc = (int)(ep - bp); if (handle->cc < 0) handle->cc = 0; return count; @@ -299,7 +299,7 @@ netfilter_stats_linux(pcap_t *handle, struct pcap_stat *stats) } static int -netfilter_inject_linux(pcap_t *handle, const void *buf _U_, size_t size _U_) +netfilter_inject_linux(pcap_t *handle, const void *buf _U_, int size _U_) { pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported on netfilter devices"); return (-1); @@ -361,7 +361,11 @@ netfilter_send_config_msg(const pcap_t *handle, uint16_t msg_type, int ack, u_in /* ignore interrupt system call error */ do { - len = recvfrom(handle->fd, buf, sizeof(buf), 0, (struct sockaddr *) &snl, &addrlen); + /* + * The buffer is not so big that its size won't + * fit into an int. + */ + len = (int)recvfrom(handle->fd, buf, sizeof(buf), 0, (struct sockaddr *) &snl, &addrlen); } while ((len == -1) && (errno == EINTR)); if (len <= 0) diff --git a/pcap-netmap.c b/pcap-netmap.c index a577d2c6..ff9e79cb 100644 --- a/pcap-netmap.c +++ b/pcap-netmap.c @@ -117,7 +117,7 @@ pcap_netmap_dispatch(pcap_t *p, int cnt, pcap_handler cb, u_char *user) /* XXX need to check the NIOCTXSYNC/poll */ static int -pcap_netmap_inject(pcap_t *p, const void *buf, size_t size) +pcap_netmap_inject(pcap_t *p, const void *buf, int size) { struct pcap_netmap *pn = p->priv; struct nm_desc *d = pn->d; @@ -197,7 +197,7 @@ pcap_read_nit(pcap_t *p, int cnt, pcap_handler callback, u_char *user) } static int -pcap_inject_nit(pcap_t *p, const void *buf, size_t size) +pcap_inject_nit(pcap_t *p, const void *buf, int size) { struct sockaddr sa; int ret; @@ -832,7 +832,7 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user) /* Send a packet to the network */ static int -pcap_inject_npf(pcap_t *p, const void *buf, size_t size) +pcap_inject_npf(pcap_t *p, const void *buf, int size) { struct pcap_win *pw = p->priv; PACKET pkt; @@ -848,7 +848,7 @@ pcap_inject_npf(pcap_t *p, const void *buf, size_t size) * "pcap_inject()" is expected to return the number of bytes * sent. */ - return ((int)size); + return (size); } static void @@ -222,7 +222,7 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user) } static int -pcap_inject_pf(pcap_t *p, const void *buf, size_t size) +pcap_inject_pf(pcap_t *p, const void *buf, int size) { int ret; diff --git a/pcap-rdmasniff.c b/pcap-rdmasniff.c index 921e68c6..a51fc7e9 100644 --- a/pcap-rdmasniff.c +++ b/pcap-rdmasniff.c @@ -361,7 +361,7 @@ rdmasniff_create(const char *device, char *ebuf, int *is_ours) int numdev; size_t namelen; const char *port; - unsigned port_num; + unsigned long port_num; int i; pcap_t *p = NULL; diff --git a/pcap-septel.c b/pcap-septel.c index dd03e23e..c8ea8eaa 100644 --- a/pcap-septel.c +++ b/pcap-septel.c @@ -180,7 +180,7 @@ loop: static int -septel_inject(pcap_t *handle, const void *buf _U_, size_t size _U_) +septel_inject(pcap_t *handle, const void *buf _U_, int size _U_) { strlcpy(handle->errbuf, "Sending packets isn't supported on Septel cards", PCAP_ERRBUF_SIZE); diff --git a/pcap-sita.c b/pcap-sita.c index 7c42791a..4a1db8e1 100644 --- a/pcap-sita.c +++ b/pcap-sita.c @@ -883,7 +883,7 @@ static void acn_start_monitor(int fd, int snaplen, int timeout, int promiscuous, //printf("acn_start_monitor() complete\n"); // fulko } -static int pcap_inject_acn(pcap_t *p, const void *buf _U_, size_t size _U_) { +static int pcap_inject_acn(pcap_t *p, const void *buf _U_, int size _U_) { strlcpy(p->errbuf, "Sending packets isn't supported on ACN adapters", PCAP_ERRBUF_SIZE); return (-1); @@ -213,7 +213,7 @@ snf_setfilter(pcap_t *p, struct bpf_program *fp) } static int -snf_inject(pcap_t *p, const void *buf _U_, size_t size _U_) +snf_inject(pcap_t *p, const void *buf _U_, int size _U_) { #ifdef SNF_HAVE_INJECT_API struct pcap_snf *ps = p->priv; diff --git a/pcap-snit.c b/pcap-snit.c index 8f2280f5..77cb07f9 100644 --- a/pcap-snit.c +++ b/pcap-snit.c @@ -208,7 +208,7 @@ pcap_read_snit(pcap_t *p, int cnt, pcap_handler callback, u_char *user) } static int -pcap_inject_snit(pcap_t *p, const void *buf, size_t size) +pcap_inject_snit(pcap_t *p, const void *buf, int size) { struct strbuf ctl, data; diff --git a/pcap-snoop.c b/pcap-snoop.c index f140bfc5..fed7c532 100644 --- a/pcap-snoop.c +++ b/pcap-snoop.c @@ -140,7 +140,7 @@ again: } static int -pcap_inject_snoop(pcap_t *p, const void *buf, size_t size) +pcap_inject_snoop(pcap_t *p, const void *buf, int size) { int ret; diff --git a/pcap-usb-linux.c b/pcap-usb-linux.c index 3412f243..4debcedc 100644 --- a/pcap-usb-linux.c +++ b/pcap-usb-linux.c @@ -136,7 +136,7 @@ static int usb_stats_linux_bin(pcap_t *, struct pcap_stat *); static int usb_read_linux(pcap_t *, int , pcap_handler , u_char *); static int usb_read_linux_bin(pcap_t *, int , pcap_handler , u_char *); static int usb_read_linux_mmap(pcap_t *, int , pcap_handler , u_char *); -static int usb_inject_linux(pcap_t *, const void *, size_t); +static int usb_inject_linux(pcap_t *, const void *, int); static int usb_setdirection_linux(pcap_t *, pcap_direction_t); static void usb_cleanup_linux_mmap(pcap_t *); @@ -145,7 +145,7 @@ have_binary_usbmon(void) { struct utsname utsname; char *version_component, *endp; - int major, minor, subminor; + long major, minor, subminor; if (uname(&utsname) == 0) { /* @@ -734,6 +734,7 @@ usb_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_cha struct pcap_usb_linux *handlep = handle->priv; unsigned timestamp; int tag, cnt, ep_num, dev_addr, dummy, ret, urb_len, data_len; + ssize_t read_ret; char etype, pipeid1, pipeid2, status[16], urb_tag, line[USB_LINE_LEN]; char *string = line; u_char * rawdata = handle->buffer; @@ -744,14 +745,14 @@ usb_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_cha /* ignore interrupt system call errors */ do { - ret = read(handle->fd, line, USB_LINE_LEN - 1); + read_ret = read(handle->fd, line, USB_LINE_LEN - 1); if (handle->break_loop) { handle->break_loop = 0; return -2; } - } while ((ret == -1) && (errno == EINTR)); - if (ret < 0) + } while ((read_ret == -1) && (errno == EINTR)); + if (read_ret < 0) { if (errno == EAGAIN) return 0; /* no data there */ @@ -763,7 +764,7 @@ usb_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_cha /* read urb header; %n argument may increment return value, but it's * not mandatory, so does not count on it*/ - string[ret] = 0; + string[read_ret] = 0; ret = sscanf(string, "%x %d %c %c%c:%d:%d %s%n", &tag, ×tamp, &etype, &pipeid1, &pipeid2, &dev_addr, &ep_num, status, &cnt); @@ -788,7 +789,7 @@ usb_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_cha return -1; } uhdr->ts_sec = pkth.ts.tv_sec; - uhdr->ts_usec = pkth.ts.tv_usec; + uhdr->ts_usec = (int32_t)pkth.ts.tv_usec; /* parse endpoint information */ if (pipeid1 == 'C') @@ -922,7 +923,7 @@ got: } static int -usb_inject_linux(pcap_t *handle, const void *buf _U_, size_t size _U_) +usb_inject_linux(pcap_t *handle, const void *buf _U_, int size _U_) { pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported on " "USB devices"); @@ -962,17 +963,17 @@ usb_stats_linux(pcap_t *handle, struct pcap_stat *stats) /* read stats line */ do { - ret = read(fd, string, USB_LINE_LEN-1); - } while ((ret == -1) && (errno == EINTR)); + read_ret = read(fd, string, USB_LINE_LEN-1); + } while ((read_ret == -1) && (errno == EINTR)); close(fd); - if (ret < 0) + if (read_ret < 0) { pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't read stats from fd %d ", fd); return -1; } - string[ret] = 0; + string[read_ret] = 0; /* extract info on dropped urbs */ for (consumed=0; consumed < ret; ) { @@ -3641,6 +3641,12 @@ pcap_cleanup_live_common(pcap_t *p) int pcap_sendpacket(pcap_t *p, const u_char *buf, int size) { + if (size <= 0) { + pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, + errno, "The number of bytes to be sent must be positive", INT_MAX); + return (PCAP_ERROR); + } + if (p->inject_op(p, buf, size) == -1) return (-1); return (0); @@ -3653,7 +3659,23 @@ pcap_sendpacket(pcap_t *p, const u_char *buf, int size) int pcap_inject(pcap_t *p, const void *buf, size_t size) { - return (p->inject_op(p, buf, size)); + /* + * We return the number of bytes written, so the number of + * bytes to write must fit in an int. + */ + if (size > INT_MAX) { + pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, + errno, "More than %d bytes cannot be injected", INT_MAX); + return (PCAP_ERROR); + } + + if (size == 0) { + pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, + errno, "The number of bytes to be injected must not be zero", INT_MAX); + return (PCAP_ERROR); + } + + return (p->inject_op(p, buf, (int)size)); } void @@ -3701,7 +3723,7 @@ pcap_read_dead(pcap_t *p, int cnt _U_, pcap_handler callback _U_, } static int -pcap_inject_dead(pcap_t *p, const void *buf _U_, size_t size _U_) +pcap_inject_dead(pcap_t *p, const void *buf _U_, int size _U_) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Packets can't be sent on a pcap_open_dead pcap_t"); @@ -216,7 +216,7 @@ sf_get_airpcap_handle(pcap_t *pcap) #endif static int -sf_inject(pcap_t *p, const void *buf _U_, size_t size _U_) +sf_inject(pcap_t *p, const void *buf _U_, int size _U_) { strlcpy(p->errbuf, "Sending packets isn't supported on savefiles", PCAP_ERRBUF_SIZE); @@ -736,7 +736,7 @@ pcap_dump(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) * 2038-01-19 03:14:07 UTC; switch to pcapng. */ sf_hdr.ts.tv_sec = (bpf_int32)h->ts.tv_sec; - sf_hdr.ts.tv_usec = h->ts.tv_usec; + sf_hdr.ts.tv_usec = (bpf_int32)h->ts.tv_usec; sf_hdr.caplen = h->caplen; sf_hdr.len = h->len; /* XXX we should check the return status */ |