From: Amos Jeffries Date: Mon, 15 Sep 2014 04:46:04 +0000 (-0700) Subject: Windows: fix various compile issues X-Git-Tag: SQUID_3_5_0_1~54 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e802a427134fee32c035b302a8ae5cca5ef2d59f;p=thirdparty%2Fsquid.git Windows: fix various compile issues * 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 --- diff --git a/src/fde.h b/src/fde.h index 42f9f54139..d202e4f137 100644 --- 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; diff --git a/src/ipc_win32.cc b/src/ipc_win32.cc index 45eba080c8..34fde64ee3 100644 --- a/src/ipc_win32.cc +++ b/src/ipc_win32.cc @@ -11,8 +11,10 @@ #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 -#ifndef _MSWSOCK_ +#if HAVE_MSWSOCK_H #include #endif #include @@ -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; } diff --git a/src/stat.cc b/src/stat.cc index 3c5c4262b7..545b3bbaac 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -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);