]> The Tcpdump Group git mirrors - libpcap/commitdiff
Fix MSVC compile warnings on the WinPcap specific code.
authorYang Luo <[email protected]>
Fri, 29 Jul 2016 08:44:59 +0000 (16:44 +0800)
committerYang Luo <[email protected]>
Fri, 29 Jul 2016 08:44:59 +0000 (16:44 +0800)
missing/win_snprintf.c
pcap-new.c
pcap-win32.c
portability.h
sockutils.c

index 6e74d859a9ed7b2276a614aa8cb0b1c7d91c95d7..65a8ea1a5cd9eee656d5453f3d65de0b19963b41 100644 (file)
@@ -6,7 +6,7 @@ pcap_vsnprintf(char *str, size_t str_size, const char *format, va_list args)
 {
        int ret;
 
-       ret = _vsnprintf(str, str_size, format, args);
+       ret = _vsnprintf_s(str, str_size, _TRUNCATE, format, args);
 
        /*
         * XXX - _vsnprintf() and _snprintf() do *not* guarantee
index b7aa886ee1c83fae0f050ae5cb142e89bc89d72b..ab48e2521e6af9fb7827506e0b9ea0e894b08170 100644 (file)
@@ -166,7 +166,7 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all
                        }
 
                        /* Copy the new device identifier into the correct memory location */
-                       strncpy(dev->name, tmpstring, strlen(tmpstring) + 1);
+                       strlcpy(dev->name, tmpstring, strlen(tmpstring) + 1);
 
 
                        /* Create the new device description */
@@ -189,7 +189,7 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all
                        }
 
                        /* Copy the new device description into the correct memory location */
-                       strncpy(dev->description, tmpstring, strlen(tmpstring) + 1);
+                       strlcpy(dev->description, tmpstring, strlen(tmpstring) + 1);
 
                        dev = dev->next;
                }
@@ -312,7 +312,7 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all
                                        return -1;
                                }
 
-                               strncpy(dev->name, tmpstring, stringlen);
+                               strlcpy(dev->name, tmpstring, stringlen);
 
                                dev->name[stringlen] = 0;
 
@@ -331,7 +331,7 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all
                                }
 
                                /* Copy the new device description into the correct memory location */
-                               strncpy(dev->description, tmpstring, stringlen + 1);
+                               strlcpy(dev->description, tmpstring, stringlen + 1);
 
                                pcap_close(fp);
                        }
@@ -514,7 +514,7 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all
                        }
 
                        /* Copy the new device name into the correct memory location */
-                       strncpy(dev->name, tmpstring2, stringlen + 1);
+                       strlcpy(dev->name, tmpstring2, stringlen + 1);
                }
 
                if (findalldevs_if.desclen)
@@ -546,7 +546,7 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all
                        }
 
                        /* Copy the new device description into the correct memory location */
-                       strncpy(dev->description, tmpstring2, stringlen + 1);
+                       strlcpy(dev->description, tmpstring2, stringlen + 1);
                }
 
                dev->flags = ntohl(findalldevs_if.flags);
@@ -668,10 +668,10 @@ int pcap_createsrcstr(char *source, int type, const char *host, const char *port
        {
        case PCAP_SRC_FILE:
        {
-               strncpy(source, PCAP_SRC_FILE_STRING, PCAP_BUF_SIZE);
+               strlcpy(source, PCAP_SRC_FILE_STRING, PCAP_BUF_SIZE);
                if ((name) && (*name))
                {
-                       strncat(source, name, PCAP_BUF_SIZE);
+                       strlcat(source, name, PCAP_BUF_SIZE);
                        return 0;
                }
                else
@@ -683,27 +683,27 @@ int pcap_createsrcstr(char *source, int type, const char *host, const char *port
 
        case PCAP_SRC_IFREMOTE:
        {
-               strncpy(source, PCAP_SRC_IF_STRING, PCAP_BUF_SIZE);
+               strlcpy(source, PCAP_SRC_IF_STRING, PCAP_BUF_SIZE);
                if ((host) && (*host))
                {
                        if ((strcspn(host, "aAbBcCdDeEfFgGhHjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ")) == strlen(host))
                        {
                                /* the host name does not contains alphabetic chars. So, it is a numeric address */
                                /* In this case we have to include it between square brackets */
-                               strncat(source, "[", PCAP_BUF_SIZE);
-                               strncat(source, host, PCAP_BUF_SIZE);
-                               strncat(source, "]", PCAP_BUF_SIZE);
+                               strlcat(source, "[", PCAP_BUF_SIZE);
+                               strlcat(source, host, PCAP_BUF_SIZE);
+                               strlcat(source, "]", PCAP_BUF_SIZE);
                        }
                        else
-                               strncat(source, host, PCAP_BUF_SIZE);
+                               strlcat(source, host, PCAP_BUF_SIZE);
 
                        if ((port) && (*port))
                        {
-                               strncat(source, ":", PCAP_BUF_SIZE);
-                               strncat(source, port, PCAP_BUF_SIZE);
+                               strlcat(source, ":", PCAP_BUF_SIZE);
+                               strlcat(source, port, PCAP_BUF_SIZE);
                        }
 
-                       strncat(source, "/", PCAP_BUF_SIZE);
+                       strlcat(source, "/", PCAP_BUF_SIZE);
                }
                else
                {
@@ -712,17 +712,17 @@ int pcap_createsrcstr(char *source, int type, const char *host, const char *port
                }
 
                if ((name) && (*name))
-                       strncat(source, name, PCAP_BUF_SIZE);
+                       strlcat(source, name, PCAP_BUF_SIZE);
 
                return 0;
        }
 
        case PCAP_SRC_IFLOCAL:
        {
-               strncpy(source, PCAP_SRC_IF_STRING, PCAP_BUF_SIZE);
+               strlcpy(source, PCAP_SRC_IF_STRING, PCAP_BUF_SIZE);
 
                if ((name) && (*name))
-                       strncat(source, name, PCAP_BUF_SIZE);
+                       strlcat(source, name, PCAP_BUF_SIZE);
 
                return 0;
        }
@@ -801,7 +801,7 @@ int pcap_parsesrcstr(const char *source, int *type, char *host, char *port, char
                                {
                                        /* We're on a local capture */
                                        if (*ptr)
-                                               strncpy(tmpname, ptr, PCAP_BUF_SIZE);
+                                               strlcpy(tmpname, ptr, PCAP_BUF_SIZE);
 
                                        /* Clean the host name, since it is a remote capture */
                                        /* NOTE: the host name has been assigned in the previous "ntoken= sscanf(...)" line */
@@ -815,9 +815,9 @@ int pcap_parsesrcstr(const char *source, int *type, char *host, char *port, char
                }
 
                if (host)
-                       strcpy(host, tmphost);
+                       strlcpy(host, tmphost, PCAP_BUF_SIZE);
                if (port)
-                       strcpy(port, tmpport);
+                       strlcpy(port, tmpport, PCAP_BUF_SIZE);
                if (type)
                        *type = tmptype;
 
@@ -830,7 +830,7 @@ int pcap_parsesrcstr(const char *source, int *type, char *host, char *port, char
                         */
                        if (tmpname[0])
                        {
-                               strcpy(name, tmpname);
+                               strlcpy(name, tmpname, PCAP_BUF_SIZE);
                        }
                        else
                        {
@@ -851,7 +851,7 @@ int pcap_parsesrcstr(const char *source, int *type, char *host, char *port, char
                if (*ptr)
                {
                        if (name)
-                               strncpy(name, ptr, PCAP_BUF_SIZE);
+                               strlcpy(name, ptr, PCAP_BUF_SIZE);
 
                        if (type)
                                *type = PCAP_SRC_FILE;
@@ -872,7 +872,7 @@ int pcap_parsesrcstr(const char *source, int *type, char *host, char *port, char
        if ((source) && (*source))
        {
                if (name)
-                       strncpy(name, source, PCAP_BUF_SIZE);
+                       strlcpy(name, source, PCAP_BUF_SIZE);
 
                if (type)
                        *type = PCAP_SRC_IFLOCAL;
@@ -979,7 +979,7 @@ pcap_t *pcap_open(const char *source, int snaplen, int flags, int read_timeout,
                break;
 
        default:
-               strcpy(errbuf, "Source type not supported");
+               strlcpy(errbuf, "Source type not supported", PCAP_ERRBUF_SIZE);
                return NULL;
        }
        return fp;
@@ -1254,7 +1254,7 @@ int pcap_remoteact_list(char *hostlist, char sep, int size, char *errbuf)
                        return -1;
                }
 
-               strcat(hostlist, hoststr);
+               strlcat(hostlist, hoststr, PCAP_ERRBUF_SIZE);
                hostlist[len - 1] = sep;
                hostlist[len] = 0;
 
index 1c993be6a1b962a496df4fd1736fa2be27024021..68d9264a62f33b9d0d7a9753fc5b06e06accaca3 100644 (file)
@@ -1225,7 +1225,7 @@ pcap_setfilter_win32_dag(pcap_t *p, struct bpf_program *fp) {
 
        if(!fp)
        {
-               strncpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf));
+               strlcpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf));
                return (-1);
        }
 
index 5a35b3619fa5e0de9fb9b5c68d5546be3f84e203..0d115b30fc469e95e5f9388b0012ba9f8d4193af 100644 (file)
@@ -79,6 +79,14 @@ extern "C" {
 
 #ifdef _MSC_VER
   #define strdup    _strdup
+  #define sscanf       sscanf_s
+char *tokbuf;
+  #define strltok(x, y) \
+       strtok_s((x), (y), &tokbuf)
+  #define strlcat(x, y, z) \
+       strncat_s((x), (z), (y), _TRUNCATE)
+#else
+  #define strltok strtok
 #endif
 
 /*
index 947637a6eb16032c502c2c191259611c8bdb46e6..0408a2faa33e01c11bd8d0f287414447985397ec 100644 (file)
@@ -862,7 +862,7 @@ int sock_check_hostlist(char *hostlist, const char *sep, struct sockaddr_storage
                        return -2;
                }
 
-               token = strtok(temphostlist, sep);
+               token = strltok(temphostlist, sep);
 
                /* it avoids a warning in the compilation ('addrinfo used but not initialized') */
                addrinfo = NULL;
@@ -886,7 +886,7 @@ int sock_check_hostlist(char *hostlist, const char *sep, struct sockaddr_storage
                                SOCK_ASSERT(errbuf, 1);
 
                                /* Get next token */
-                               token = strtok(NULL, sep);
+                               token = strltok(NULL, sep);
                                continue;
                        }
 
@@ -911,7 +911,7 @@ int sock_check_hostlist(char *hostlist, const char *sep, struct sockaddr_storage
                        addrinfo = NULL;
 
                        /* Get next token */
-                       token = strtok(NULL, sep);
+                       token = strltok(NULL, sep);
                }
 
                if (addrinfo)
@@ -1105,7 +1105,7 @@ int sock_getascii_addrport(const struct sockaddr_storage *sockaddr, char *addres
                        (memcmp(&((struct sockaddr_in6 *) sockaddr)->sin6_addr, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", sizeof(struct in6_addr)) == 0))
                {
                        if (address)
-                               strncpy(address, SOCKET_NAME_NULL_DAD, addrlen);
+                               strlcpy(address, SOCKET_NAME_NULL_DAD, addrlen);
                        return retval;
                }
        }
@@ -1121,13 +1121,13 @@ int sock_getascii_addrport(const struct sockaddr_storage *sockaddr, char *addres
 
                if (address)
                {
-                       strncpy(address, SOCKET_NO_NAME_AVAILABLE, addrlen);
+                       strlcpy(address, SOCKET_NO_NAME_AVAILABLE, addrlen);
                        address[addrlen - 1] = 0;
                }
 
                if (port)
                {
-                       strncpy(port, SOCKET_NO_PORT_AVAILABLE, portlen);
+                       strlcpy(port, SOCKET_NO_PORT_AVAILABLE, portlen);
                        port[portlen - 1] = 0;
                }