]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Windows: fix various compile issues
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 15 Sep 2014 04:46:04 +0000 (21:46 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 15 Sep 2014 04:46:04 +0000 (21:46 -0700)
* syntax error typo from SBuf conversion of service_name

* add several missing includes

* fix macro wrapper around mswsock.h

* in ipc_win2.cc fix parameter error for memset() and several potential
  buffer overruns by removing magic number parameters on buffer size.

* fdd_table entry is not a HANDLE but a function pointer

src/fde.h
src/ipc_win32.cc
src/stat.cc

index 42f9f54139bf68e999f0de842f9a336be0ff4dd8..d202e4f137ebafed4bdb62df2238f0a844f766cb 100644 (file)
--- a/src/fde.h
+++ b/src/fde.h
@@ -166,7 +166,7 @@ private:
         dynamicSslContext = NULL;
 #endif
 #if _SQUID_WINDOWS_
-        win32.handle = NULL;
+        win32.handle = (long)NULL;
 #endif
         tosFromServer = '\0';
         nfmarkFromServer = 0;
index 45eba080c8e217176975b0fd6d033caaf728d3fc..34fde64ee3a8c364eaa27aa72165e0ebcee0e1c6 100644 (file)
 #include "squid.h"
 #include "cache_cf.h"
 #include "comm.h"
+#include "comm/Connection.h"
 #include "fd.h"
 #include "fde.h"
+#include "globals.h"
 #include "ip/Address.h"
 #include "rfc1738.h"
 #include "SquidConfig.h"
@@ -21,7 +23,7 @@
 #include "tools.h"
 
 #include <cerrno>
-#ifndef _MSWSOCK_
+#if HAVE_MSWSOCK_H
 #include <mswsock.h>
 #endif
 #include <process.h>
@@ -375,7 +377,8 @@ ipc_thread_1(void *in_params)
     Ip::Address PS = params->PS;
     Ip::Address local_addr = params->local_addr;
 
-    buf1 = (char *)xcalloc(1, 8192);
+    const size_t bufSz = 8192;
+    buf1 = (char *)xcalloc(1, bufSz);
     strcpy(buf1, params->prog);
     prog = strtok(buf1, w_space);
 
@@ -397,7 +400,7 @@ ipc_thread_1(void *in_params)
 
         debugs(54, 3, "ipcCreate: CHILD accepted new FD " << fd);
         comm_close(crfd);
-        snprintf(buf1, 8191, "%s CHILD socket", prog);
+        snprintf(buf1, bufSz-1, "%s CHILD socket", prog);
         fd_open(fd, FD_SOCKET, buf1);
         fd_table[fd].flags.ipc = 1;
         cwfd = crfd = fd;
@@ -415,8 +418,8 @@ ipc_thread_1(void *in_params)
     }
 
     PutEnvironment();
-    memset(buf1, '\0', sizeof(buf1));
-    x = recv(crfd, (void *)buf1, 8191, 0);
+    memset(buf1, '\0', bufSz);
+    x = recv(crfd, (void *)buf1, bufSz-1, 0);
 
     if (x < 0) {
         debugs(54, DBG_CRITICAL, "ipcCreate: CHILD: OK read test failed");
@@ -443,7 +446,7 @@ ipc_thread_1(void *in_params)
     }
 
     if (type == IPC_UDP_SOCKET) {
-        snprintf(buf1, 8192, "%s(%ld) <-> ipc CHILD socket", prog, -1L);
+        snprintf(buf1, bufSz, "%s(%ld) <-> ipc CHILD socket", prog, -1L);
         crfd_ipc = cwfd_ipc = comm_open(SOCK_DGRAM, IPPROTO_UDP, local_addr, 0, buf1);
 
         if (crfd_ipc < 0) {
@@ -452,7 +455,7 @@ ipc_thread_1(void *in_params)
             goto cleanup;
         }
 
-        snprintf(buf1, 8192, "%s(%ld) <-> ipc PARENT socket", prog, -1L);
+        snprintf(buf1, bufSz, "%s(%ld) <-> ipc PARENT socket", prog, -1L);
         prfd_ipc = pwfd_ipc = comm_open(SOCK_DGRAM, IPPROTO_UDP, local_addr, 0, buf1);
 
         if (pwfd_ipc < 0) {
@@ -603,7 +606,7 @@ ipc_thread_1(void *in_params)
             goto cleanup;
         }
 
-        x = read(p2c[0], buf1, 8192);
+        x = read(p2c[0], buf1, bufSz-1);
 
         if (x < 0) {
             debugs(54, DBG_CRITICAL, "ipcCreate: CHILD: read FD " << p2c[0] << ": " << xstrerror());
@@ -630,7 +633,7 @@ ipc_thread_1(void *in_params)
             goto cleanup;
         }
 
-        x = read(p2c[0], buf1, 8192);
+        x = read(p2c[0], buf1, bufSz-1);
 
         if (x < 0) {
             debugs(54, DBG_CRITICAL, "ipcCreate: CHILD: read FD " << p2c[0] << ": " << xstrerror());
@@ -648,19 +651,19 @@ ipc_thread_1(void *in_params)
         }
 
         x = send(pwfd_ipc, (const void *)ok_string, strlen(ok_string), 0);
-        x = recv(prfd_ipc, (void *)(buf1 + 200), 8191 - 200, 0);
+        x = recv(prfd_ipc, (void *)(buf1 + 200), bufSz -1 - 200, 0);
         assert((size_t) x == strlen(ok_string)
                && !strncmp(ok_string, buf1 + 200, strlen(ok_string)));
     }                          /* IPC_UDP_SOCKET */
 
-    snprintf(buf1, 8191, "%s(%ld) CHILD socket", prog, (long int) pid);
+    snprintf(buf1, bufSz-1, "%s(%ld) CHILD socket", prog, (long int) pid);
 
     fd_note(fd, buf1);
 
     if (prfd_ipc != -1) {
-        snprintf(buf1, 8191, "%s(%ld) <-> ipc CHILD socket", prog, (long int) pid);
+        snprintf(buf1, bufSz-1, "%s(%ld) <-> ipc CHILD socket", prog, (long int) pid);
         fd_note(crfd_ipc, buf1);
-        snprintf(buf1, 8191, "%s(%ld) <-> ipc PARENT socket", prog, (long int) pid);
+        snprintf(buf1, bufSz-1, "%s(%ld) <-> ipc PARENT socket", prog, (long int) pid);
         fd_note(prfd_ipc, buf1);
     }
 
@@ -686,7 +689,7 @@ ipc_thread_1(void *in_params)
         goto cleanup;
     }
 
-    snprintf(buf1, 8191, "%ld\n", (long int) pid);
+    snprintf(buf1, bufSz-1, "%ld\n", (long int) pid);
 
     if (-1 == ipcSend(cwfd, buf1, strlen(buf1)))
         goto cleanup;
@@ -695,7 +698,7 @@ ipc_thread_1(void *in_params)
 
     /* cycle */
     for (;;) {
-        x = recv(crfd, (void *)buf1, 8192, 0);
+        x = recv(crfd, (void *)buf1, bufSz-1, 0);
 
         if (x <= 0) {
             debugs(54, 3, "ipc(" << prog << "," << pid << "): " << x << " bytes received from parent. Exiting...");
@@ -763,11 +766,8 @@ cleanup:
     if (!retval)
         debugs(54, 2, "ipc(" << prog << "," << pid << "): normal exit");
 
-    if (buf1)
-        xfree(buf1);
-
-    if (prog)
-        xfree(prog);
+    xfree(buf1);
+    xfree(prog);
 
     if (thread)
         CloseHandle(thread);
@@ -792,13 +792,14 @@ ipc_thread_2(void *in_params)
     int send_fd = params->send_fd;
     char *prog = xstrdup(params->prog);
     pid_t pid = params->pid;
-    char *buf2 = (char *)xcalloc(1, 8192);
+    const size_t bufSz = 8192;
+    char *buf2 = (char *)xcalloc(1, bufSz);
 
     for (;;) {
         if (type == IPC_TCP_SOCKET)
-            x = read(rfd, buf2, 8192);
+            x = read(rfd, buf2, bufSz-1);
         else
-            x = recv(rfd, (void *)buf2, 8192, 0);
+            x = recv(rfd, (void *)buf2, bufSz-1, 0);
 
         if ((x <= 0 && type == IPC_TCP_SOCKET) ||
                 (x < 0 && type == IPC_UDP_SOCKET)) {
@@ -811,7 +812,6 @@ ipc_thread_2(void *in_params)
 
         if (type == IPC_UDP_SOCKET && !strcmp(buf2, shutdown_string)) {
             debugs(54, 3, "ipc(" << prog << "," << pid << "): request for shutdown received. Exiting...");
-
             break;
         }
 
index 3c5c4262b7c3d14d557ae6f3749526b4e618e01a..545b3bbaac7b2dc789e1262f983bc4995601c7be 100644 (file)
@@ -604,7 +604,7 @@ DumpInfo(Mgr::InfoActionData& stats, StoreEntry* sentry)
 #if _SQUID_WINDOWS_
     if (WIN32_run_mode == _WIN_SQUID_RUN_MODE_SERVICE) {
         storeAppendPrintf(sentry,"\nRunning as " SQUIDSBUFPH " Windows System Service on %s\n",
-                          SQUIDBUFPRINT(service_name), WIN32_OS_string);
+                          SQUIDSBUFPRINT(service_name), WIN32_OS_string);
         storeAppendPrintf(sentry,"Service command line is: %s\n", WIN32_Service_Command_Line);
     } else
         storeAppendPrintf(sentry,"Running on %s\n",WIN32_OS_string);