rjung
Tue, 14 Oct 2008 07:20:19 -0700
Author: rjung Date: Tue Oct 14 07:19:56 2008 New Revision: 704548 URL: http://svn.apache.org/viewvc?rev=704548&view=rev Log: Prevent IIS memory corruption due to multiple concurrent initializations. Modified: tomcat/connectors/trunk/jk/native/common/jk_shm.c tomcat/connectors/trunk/jk/native/iis/jk_isapi_plugin.c tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml Modified: tomcat/connectors/trunk/jk/native/common/jk_shm.c URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_shm.c?rev=704548&r1=704547&r2=704548&view=diff ============================================================================== --- tomcat/connectors/trunk/jk/native/common/jk_shm.c (original) +++ tomcat/connectors/trunk/jk/native/common/jk_shm.c Tue Oct 14 07:19:56 2008 @@ -242,7 +242,7 @@ if (jk_shmem.hdr->h.data.childs > 1) { if (JK_IS_DEBUG_LEVEL(l)) { jk_log(l, JK_LOG_DEBUG, - "Reseting the shared memory for child %d", + "Resetting the shared memory for child %d", jk_shmem.hdr->h.data.childs); } } @@ -562,7 +562,7 @@ if (nchild > 1) { if (JK_IS_DEBUG_LEVEL(l)) { jk_log(l, JK_LOG_DEBUG, - "Reseting the shared memory for child %d", + "Resetting the shared memory for child %d", nchild); } } Modified: tomcat/connectors/trunk/jk/native/iis/jk_isapi_plugin.c URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/iis/jk_isapi_plugin.c?rev=704548&r1=704547&r2=704548&view=diff ============================================================================== --- tomcat/connectors/trunk/jk/native/iis/jk_isapi_plugin.c (original) +++ tomcat/connectors/trunk/jk/native/iis/jk_isapi_plugin.c Tue Oct 14 07:19:56 2008 @@ -474,6 +474,7 @@ static char dll_file_path[MAX_PATH]; static char ini_file_name[MAX_PATH]; static int using_ini_file = JK_FALSE; +static JK_CRIT_SEC init_cs; static int is_inited = JK_FALSE; static int is_mapread = JK_FALSE; @@ -1405,6 +1406,7 @@ BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pVer) { + int rc; BOOL rv = TRUE; ULONG http_filter_revision = HTTP_FILTER_REVISION; @@ -1413,9 +1415,11 @@ if (pVer->dwFilterVersion > http_filter_revision) { pVer->dwFilterVersion = http_filter_revision; } + JK_ENTER_CS(&(init_cs), rc); if (!is_inited) { rv = initialize_extension(); } + JK_LEAVE_CS(&(init_cs), rc); pVer->dwFlags = SF_NOTIFY_ORDER_HIGH | SF_NOTIFY_SECURE_PORT | SF_NOTIFY_NONSECURE_PORT | @@ -1752,11 +1756,11 @@ return 0; } -static int init_error = 0; - DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD dwNotificationType, LPVOID pvNotification) { + int rc; + /* Initialise jk */ if (is_inited && !is_mapread) { char serverName[MAX_SERVERNAME] = ""; @@ -1775,8 +1779,10 @@ } } } - if (init_jk(serverName)) + JK_ENTER_CS(&(init_cs), rc); + if (!is_mapread && init_jk(serverName)) is_mapread = JK_TRUE; + JK_LEAVE_CS(&(init_cs), rc); } /* If we can't read the map we become dormant */ if (!is_mapread) @@ -2081,20 +2087,25 @@ BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO * pVer) { + int rc; + pVer->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR); StringCbCopy(pVer->lpszExtensionDesc, HSE_MAX_EXT_DLL_NAME_LEN, (VERSION_STRING)); + JK_ENTER_CS(&(init_cs), rc); if (!is_inited) { return initialize_extension(); } + JK_LEAVE_CS(&(init_cs), rc); return TRUE; } DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpEcb) { + int rv; DWORD rc = HSE_STATUS_ERROR; lpEcb->dwHttpStatusCode = HTTP_STATUS_SERVER_ERROR; @@ -2121,8 +2132,10 @@ } } } - if (init_jk(serverName)) + JK_ENTER_CS(&(init_cs), rv); + if (!is_mapread && init_jk(serverName)) is_mapread = JK_TRUE; + JK_LEAVE_CS(&(init_cs), rv); } if (!is_mapread) is_inited = JK_FALSE; @@ -2227,9 +2240,13 @@ BOOL WINAPI TerminateFilter(DWORD dwFlags) { + int rc; + UNREFERENCED_PARAMETER(dwFlags); + JK_ENTER_CS(&(init_cs), rc); if (is_inited) { + jk_log(logger, JK_LOG_INFO, "%s stopping", (VERSION_STRING)); is_inited = JK_FALSE; watchdog_interval = 0; if (watchdog_handle) { @@ -2264,6 +2281,7 @@ jk_close_file_logger(&logger); } } + JK_LEAVE_CS(&(init_cs), rc); return TRUE; } @@ -2273,6 +2291,7 @@ ULONG ulReason, // Reason why NT called this DLL LPVOID lpReserved) // Reserved parameter for future use { + int rc; BOOL fReturn = TRUE; char fname[MAX_PATH]; @@ -2318,6 +2337,8 @@ StringCbPrintf(HTTP_WORKER_HEADER_NAME, MAX_PATH, HTTP_HEADER_TEMPLATE, WORKER_HEADER_NAME_BASE, hInst); StringCbPrintf(HTTP_WORKER_HEADER_INDEX, MAX_PATH, HTTP_HEADER_TEMPLATE, WORKER_HEADER_INDEX_BASE, hInst); + JK_INIT_CS(&init_cs, rc); + break; case DLL_PROCESS_DETACH: __try { @@ -2325,6 +2346,7 @@ } __except(1) { } + JK_DELETE_CS(&init_cs, rc); break; default: Modified: tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml?rev=704548&r1=704547&r2=704548&view=diff ============================================================================== --- tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml (original) +++ tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml Tue Oct 14 07:19:56 2008 @@ -43,6 +43,9 @@ <br /> <subsection name="Native"> <changelog> + <fix>IIS: Fix memory corruption due to parallel initialization + by multiple threads. (rjung) + </fix> <update> Added socket_connect_timeout directive for setting the connect timeout for the socket. This enables to have low --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]