]> The Tcpdump Group git mirrors - libpcap/commitdiff
Squelch more narrowing warnings.
authorGuy Harris <[email protected]>
Thu, 13 Sep 2018 02:41:38 +0000 (19:41 -0700)
committerGuy Harris <[email protected]>
Thu, 13 Sep 2018 03:18:59 +0000 (20:18 -0700)
25 files changed:
diag-control.h
pcap-bpf.c
pcap-bt-linux.c
pcap-bt-monitor-linux.c
pcap-dag.c
pcap-dbus.c
pcap-dlpi.c
pcap-int.h
pcap-libdlpi.c
pcap-linux.c
pcap-netfilter-linux.c
pcap-netmap.c
pcap-nit.c
pcap-npf.c
pcap-pf.c
pcap-rdmasniff.c
pcap-septel.c
pcap-sita.c
pcap-snf.c
pcap-snit.c
pcap-snoop.c
pcap-usb-linux.c
pcap.c
savefile.c
sf-pcap.c

index cfc581b37b57ca7b43e7efba717f42eb6249756f..f710c6c17da539342ffa49e6b9fd4c26658b9527 100644 (file)
     __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
     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.
     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
    */
   #define DIAG_OFF_FLEX
   #define DIAG_ON_FLEX
+  #define DIAG_OFF_NARROWING
+  #define DIAG_ON_NARROWING
 #endif
 
 #ifdef YYBYACC
index 8a8e8a153c78d446922759a7021c61a9e33ece2a..a3247c56c89c5e7a4ef985046cd8a052bb407c03 100644 (file)
@@ -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
index 0c21d9c1a196a144bb06c85709c71e8015ea34b3..a0765b5b3150bd35cc8c7f2f0bdb059ec61969fb 100644 (file)
@@ -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");
index 4f12712753baa8c271b8eb3302f1785a1f7ab8a3..00d48798f293d2a9635c3a8df7363e861d9127ea 100644 (file)
@@ -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;
index be784b46011dad7491d72a0559d9a021f8360cc9..d992a4935e44040135c72634be1538e06248ef77 100644 (file)
@@ -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);
index 9f426e671bb0fd1d1473e4734e4281ed85a81798..6b26d8ab741e87b098b7a5f9ea959df9b41632af 100644 (file)
@@ -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;
index 09cb6d449eea17600b460e9f244f9b139c170da0..389b2ac5969755e7d41d108177615b276a65b134 100644 (file)
@@ -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;
index 2426ab107d3b295e004d570b7bfc259218218325..99e7af789289a0a2c265d3108828be60a559d053 100644 (file)
@@ -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);
index a0d16693f6c2e26022e6df18b0891185ce1ea58c..af167212f2b83793f771762d08fc4b67230af683 100644 (file)
@@ -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;
index 54592e668fa04fc99aa7ffe9239d3e218f67a25e..4e4a54949bd4fe21fd2fe8a6fafa0677a59a2e9b 100644 (file)
@@ -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:
index 675df4aede0a26a308c683d9b6d5c42a19cb4444..e2cfe841a752d3263ad0e7ee80edfad42e7fbb86 100644 (file)
@@ -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)
index a577d2c6a716b4bbfcdf5d3ac1200e33bad72fa1..ff9e79cb40f6e843ed90facb956ad19be160a87e 100644 (file)
@@ -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;
index c011a6a536faaf5c1b61af3677357ffe2dac9175..e969359414eed05bbcfd7a43051c5ccf48472e2b 100644 (file)
@@ -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;
index 347c537a8655dcc40ccb7c48ac9283240da4a7ce..842f4c9e25e45d31f16a30f974673d4e7f0800a7 100644 (file)
@@ -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
index c712460fb8a13b5aaa03fd8f60957d3795d69d78..8e1febdc1a32ac05d315a9402588a22222f70853 100644 (file)
--- a/pcap-pf.c
+++ b/pcap-pf.c
@@ -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;
 
index 921e68c6c450b9f35111be0384441ee4f201ea0a..a51fc7e987a6d1bb5f4bd6490513c1e505b44c0a 100644 (file)
@@ -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;
 
index dd03e23e8f25b160dff3333524603c9fee2b1b55..c8ea8eaad8835850516ff22eb8bfd15599fc4d77 100644 (file)
@@ -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);
index 7c42791aab8b730281fc986db70ade6bab8d478f..4a1db8e1398626de11feb12946827963f6c377fb 100644 (file)
@@ -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);
index 3d4fea9ffc36fb8f0df7c8f877973fe815494cce..df70cbe35010d49dfb92aca1de7d7fcabaa85bbd 100644 (file)
@@ -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;
index 8f2280f5069ca1ac0e6642c6e89df324e4c85ae4..77cb07f9c82b8f0c044a3903c40e44e5667bd2d2 100644 (file)
@@ -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;
 
index f140bfc5718dfaead3956b7cad9f97b926f547c7..fed7c532f5c71d7819a6c6ed78c4667de4c1816a 100644 (file)
@@ -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;
 
index 3412f2434ebacf5eb8c5382b815a8fac94508987..4debcedc2ab07c91f1b4ca3969cf841a02a1aac5 100644 (file)
@@ -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, &timestamp, &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; ) {
diff --git a/pcap.c b/pcap.c
index f856bd64ebf2034c767f16497b7b1dc5bedc91e0..4d135aa286554bfdd40060f645d90af2d01d4753 100644 (file)
--- a/pcap.c
+++ b/pcap.c
@@ -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");
index 15b1f183b62d5b8e8a34cf5eb93cf5442d680607..cf65d68747b6e4fdfc3429fd6cf13ebcb35c4ffd 100644 (file)
@@ -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);
index 9e52a8bb68bb0bfe6f71f25cef185bd8a93d8e03..40eab03dd28931d4ec174aa7cea09bf4439c7985 100644 (file)
--- a/sf-pcap.c
+++ b/sf-pcap.c
@@ -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 */