------------------------------------------------------------ revno: 13591 revision-id: squid3@treenet.co.nz-20140915044604-qofiimqqwzneneww parent: squid3@treenet.co.nz-20140915025433-yb4ldlmqhvfgi6nx committer: Amos Jeffries branch nick: trunk timestamp: Sun 2014-09-14 21:46:04 -0700 message: 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 ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20140915044604-qofiimqqwzneneww # target_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: 3115b868a00ae3a4e09c66266149037b86b61d64 # timestamp: 2014-09-15 10:53:27 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # base_revision_id: squid3@treenet.co.nz-20140915025433-\ # yb4ldlmqhvfgi6nx # # Begin patch === modified file 'src/fde.h' --- src/fde.h 2014-09-13 13:59:43 +0000 +++ src/fde.h 2014-09-15 04:46:04 +0000 @@ -166,7 +166,7 @@ dynamicSslContext = NULL; #endif #if _SQUID_WINDOWS_ - win32.handle = NULL; + win32.handle = (long)NULL; #endif tosFromServer = '\0'; nfmarkFromServer = 0; === modified file 'src/ipc_win32.cc' --- src/ipc_win32.cc 2014-09-13 13:59:43 +0000 +++ src/ipc_win32.cc 2014-09-15 04:46:04 +0000 @@ -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 @@ 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 @@ 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 @@ } 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 @@ } 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 @@ 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 @@ 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 @@ 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 @@ } 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 @@ 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 @@ /* 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 @@ 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 @@ 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 @@ if (type == IPC_UDP_SOCKET && !strcmp(buf2, shutdown_string)) { debugs(54, 3, "ipc(" << prog << "," << pid << "): request for shutdown received. Exiting..."); - break; } === modified file 'src/stat.cc' --- src/stat.cc 2014-09-13 13:59:43 +0000 +++ src/stat.cc 2014-09-15 04:46:04 +0000 @@ -604,7 +604,7 @@ #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);