From b15f501b1660ac472a97e971a0ea0a90d0996baf Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Fri, 6 Oct 2000 22:33:44 +0000 Subject: [PATCH] Roll forward fixes identified for 1.3.13-dev. Note... this module still needs more control over async emulation, etc. Submitted by: Jesse Pelton [jsp@PKC.com] git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@86422 13f79535-47bb-0310-9956-ffa450edef68 --- modules/arch/win32/mod_isapi.c | 123 +++++++++++++++++---------------- os/win32/mod_isapi.c | 123 +++++++++++++++++---------------- 2 files changed, 126 insertions(+), 120 deletions(-) diff --git a/modules/arch/win32/mod_isapi.c b/modules/arch/win32/mod_isapi.c index 9470b27d85..3d02d9ee2e 100644 --- a/modules/arch/win32/mod_isapi.c +++ b/modules/arch/win32/mod_isapi.c @@ -557,6 +557,7 @@ BOOL WINAPI GetServerVariable (HCONN hConn, LPSTR lpszVariableName, { request_rec *r = ((isapi_cid *)hConn)->r; const char *result; + DWORD len; if (!strcmp(lpszVariableName, "ALL_HTTP")) { @@ -564,23 +565,20 @@ BOOL WINAPI GetServerVariable (HCONN hConn, LPSTR lpszVariableName, * null terminated list of HTTP_ vars */ char **env = (char**) apr_table_elts(r->subprocess_env)->elts; - int n = apr_table_elts(r->subprocess_env)->nelts; - DWORD len = 0; - int i = 0; + int nelts = 2 * apr_table_elts(r->subprocess_env)->nelts; + int i; - while (i < n * 2) { + for (len = 0, i = 0; i < nelts; i += 2) if (!strncmp(env[i], "HTTP_", 5)) len += strlen(env[i]) + strlen(env[i + 1]) + 2; - i += 2; - } if (*lpdwSizeofBuffer < len + 1) { + *lpdwSizeofBuffer = len + 1; SetLastError(ERROR_INSUFFICIENT_BUFFER); return FALSE; } - i = 0; - while (i < n * 2) { + for (i = 0; i < nelts; i += 2) if (!strncmp(env[i], "HTTP_", 5)) { strcpy(lpvBuffer, env[i]); ((char*)lpvBuffer) += strlen(env[i]); @@ -589,34 +587,31 @@ BOOL WINAPI GetServerVariable (HCONN hConn, LPSTR lpszVariableName, ((char*)lpvBuffer) += strlen(env[i + 1]); *(((char*)lpvBuffer)++) = '\n'; } - i += 2; - } + *(((char*)lpvBuffer)++) = '\0'; *lpdwSizeofBuffer = len; return TRUE; } - else if (!strcmp(lpszVariableName, "ALL_RAW")) + + if (!strcmp(lpszVariableName, "ALL_RAW")) { /* lf delimited, colon split, comma seperated and * null terminated list of the raw request header */ char **raw = (char**) apr_table_elts(r->headers_in)->elts; - int n = apr_table_elts(r->headers_in)->nelts; - DWORD len = 0; - int i = 0; + int nelts = 2 * apr_table_elts(r->headers_in)->nelts; + int i; - while (i < n * 2) { + for (i = 0; i < nelts; i += 2) len += strlen(raw[i]) + strlen(raw[i + 1]) + 2; - i += 2; - } if (*lpdwSizeofBuffer < len + 1) { + *lpdwSizeofBuffer = len + 1; SetLastError(ERROR_INSUFFICIENT_BUFFER); return FALSE; } - i = 0; - while (i < n * 2) { + for (i = 0; i < nelts; i += 2) { strcpy(lpvBuffer, raw[i]); ((char*)lpvBuffer) += strlen(raw[i]); *(((char*)lpvBuffer)++) = ':'; @@ -630,21 +625,23 @@ BOOL WINAPI GetServerVariable (HCONN hConn, LPSTR lpszVariableName, *lpdwSizeofBuffer = len; return TRUE; } - else { - result = apr_table_get(r->subprocess_env, lpszVariableName); - } + + /* Not a special case */ + result = apr_table_get(r->subprocess_env, lpszVariableName); if (result) { - if (strlen(result) > *lpdwSizeofBuffer) { - *lpdwSizeofBuffer = strlen(result); + len = strlen(result); + if (*lpdwSizeofBuffer < len + 1) { + *lpdwSizeofBuffer = len + 1; SetLastError(ERROR_INSUFFICIENT_BUFFER); return FALSE; } - strncpy(lpvBuffer, result, *lpdwSizeofBuffer); + strcpy(lpvBuffer, result); + *lpdwSizeofBuffer = len; return TRUE; } - /* Didn't find it - should this be ERROR_NO_DATA? */ + /* Not Found */ SetLastError(ERROR_INVALID_INDEX); return FALSE; } @@ -701,34 +698,34 @@ BOOL WINAPI ReadClient (HCONN ConnID, LPVOID lpvBuffer, LPDWORD lpdwSize) } static BOOL SendResponseHeaderEx(isapi_cid *cid, const char *stat, - const char *head, size_t statlen, - size_t headlen) + const char *head, DWORD statlen, + DWORD headlen) { int termarg; char *termch; - if (!stat || !*stat) { + if (!stat || statlen == 0 || !*stat) { stat = "Status: 200 OK"; } else { char *newstat; - if (statlen == 0) - statlen = strlen(stat); - /* Whoops... not NULL terminated */ newstat = apr_palloc(cid->r->pool, statlen + 9); strcpy(newstat, "Status: "); - strncpy(newstat + 8, stat, statlen); + apr_cpystrn(newstat + 8, stat, statlen + 1); stat = newstat; } - if (!head || !*head) { + if (!head || headlen == 0 || !*head) { head = "\r\n"; } - else if ((headlen >= 0) && head[headlen]) { - /* Whoops... not NULL terminated */ - head = apr_pstrndup(cid->r->pool, head, headlen); + else + { + if (head[headlen]) { + /* Whoops... not NULL terminated */ + head = apr_pstrndup(cid->r->pool, head, headlen); + } } - + /* Parse them out, or die trying */ cid->r->status= ap_scan_script_header_err_strs(cid->r, NULL, &termch, &termarg, stat, head, NULL); @@ -794,35 +791,42 @@ BOOL WINAPI ServerSupportFunction (HCONN hConn, DWORD dwHSERequest, return TRUE; case 3: /* HSE_REQ_SEND_RESPONSE_HEADER */ + { /* Parse them out, or die trying */ - return SendResponseHeaderEx(cid, (char*) lpvBuffer, - (char*) lpdwDataType, -1, -1); - + DWORD statlen = 0, headlen = 0; + if (lpvBuffer) + statlen = strlen((char*) lpvBuffer); + if (lpdwDataType) + headlen = strlen((char*) lpdwDataType); + return SendResponseHeaderEx(cid, (char*) lpvBuffer, (char*) lpdwDataType, + statlen, headlen); + } - case HSE_REQ_DONE_WITH_SESSION: - /* Signal to resume the thread completing this request - */ - if (cid->complete) - SetEvent(cid->complete); - return TRUE; + case 4: /* HSE_REQ_DONE_WITH_SESSION */ + /* Signal to resume the thread completing this request + */ + if (cid->complete) + SetEvent(cid->complete); + return TRUE; case 1001: /* HSE_REQ_MAP_URL_TO_PATH */ { /* Map a URL to a filename */ char *file = (char *)lpvBuffer; + DWORD len; subreq = ap_sub_req_lookup_uri(apr_pstrndup(r->pool, file, *lpdwSize), r); - strncpy(file, subreq->filename, *lpdwSize - 1); - file[*lpdwSize - 1] = '\0'; + len = apr_cpystrn(file, subreq->filename, *lpdwSize) - file; + /* IIS puts a trailing slash on directories, Apache doesn't */ if (subreq->finfo.filetype == APR_DIR) { - DWORD l = strlen(file); - if (l < *lpdwSize - 1) { - file[l] = '\\'; - file[l + 1] = '\0'; + if (len < *lpdwSize - 1) { + file[len++] = '\\'; + file[len] = '\0'; } } + *lpdwSize = len; return TRUE; } @@ -912,17 +916,17 @@ BOOL WINAPI ServerSupportFunction (HCONN hConn, DWORD dwHSERequest, char* test_uri = apr_pstrndup(r->pool, (char *)lpvBuffer, *lpdwSize); subreq = ap_sub_req_lookup_uri(test_uri, r); - info->lpszPath[MAX_PATH - 1] = '\0'; - strncpy(info->lpszPath, subreq->filename, MAX_PATH - 1); info->cchMatchingURL = strlen(test_uri); - info->cchMatchingPath = strlen(info->lpszPath); + info->cchMatchingPath = apr_cpystrn(info->lpszPath, subreq->filename, + MAX_PATH) - info->lpszPath; + /* Mapping started with assuming both strings matched. * Now roll on the path_info as a mismatch and handle * terminating slashes for directory matches. */ if (subreq->path_info && *subreq->path_info) { - strncpy(info->lpszPath + info->cchMatchingPath, subreq->path_info, - MAX_PATH - info->cchMatchingPath - 1); + apr_cpystrn(info->lpszPath + info->cchMatchingPath, + subreq->path_info, MAX_PATH - info->cchMatchingPath); info->cchMatchingURL -= strlen(subreq->path_info); if (subreq->finfo.filetype == APR_DIR && info->cchMatchingPath < MAX_PATH - 1) { @@ -1012,8 +1016,7 @@ BOOL WINAPI ServerSupportFunction (HCONN hConn, DWORD dwHSERequest, case 1018: /* HSE_REQ_IS_CONNECTED Added after ISAPI 4.0 */ /* Returns True if client is connected c.f. MSKB Q188346 - * XXX: That statement is very ambigious... assuming the - * identical return mechanism as HSE_REQ_IS_KEEP_CONN. + * assuming the identical return mechanism as HSE_REQ_IS_KEEP_CONN */ *((LPBOOL) lpvBuffer) = (r->connection->aborted == 0); return TRUE; diff --git a/os/win32/mod_isapi.c b/os/win32/mod_isapi.c index 9470b27d85..3d02d9ee2e 100644 --- a/os/win32/mod_isapi.c +++ b/os/win32/mod_isapi.c @@ -557,6 +557,7 @@ BOOL WINAPI GetServerVariable (HCONN hConn, LPSTR lpszVariableName, { request_rec *r = ((isapi_cid *)hConn)->r; const char *result; + DWORD len; if (!strcmp(lpszVariableName, "ALL_HTTP")) { @@ -564,23 +565,20 @@ BOOL WINAPI GetServerVariable (HCONN hConn, LPSTR lpszVariableName, * null terminated list of HTTP_ vars */ char **env = (char**) apr_table_elts(r->subprocess_env)->elts; - int n = apr_table_elts(r->subprocess_env)->nelts; - DWORD len = 0; - int i = 0; + int nelts = 2 * apr_table_elts(r->subprocess_env)->nelts; + int i; - while (i < n * 2) { + for (len = 0, i = 0; i < nelts; i += 2) if (!strncmp(env[i], "HTTP_", 5)) len += strlen(env[i]) + strlen(env[i + 1]) + 2; - i += 2; - } if (*lpdwSizeofBuffer < len + 1) { + *lpdwSizeofBuffer = len + 1; SetLastError(ERROR_INSUFFICIENT_BUFFER); return FALSE; } - i = 0; - while (i < n * 2) { + for (i = 0; i < nelts; i += 2) if (!strncmp(env[i], "HTTP_", 5)) { strcpy(lpvBuffer, env[i]); ((char*)lpvBuffer) += strlen(env[i]); @@ -589,34 +587,31 @@ BOOL WINAPI GetServerVariable (HCONN hConn, LPSTR lpszVariableName, ((char*)lpvBuffer) += strlen(env[i + 1]); *(((char*)lpvBuffer)++) = '\n'; } - i += 2; - } + *(((char*)lpvBuffer)++) = '\0'; *lpdwSizeofBuffer = len; return TRUE; } - else if (!strcmp(lpszVariableName, "ALL_RAW")) + + if (!strcmp(lpszVariableName, "ALL_RAW")) { /* lf delimited, colon split, comma seperated and * null terminated list of the raw request header */ char **raw = (char**) apr_table_elts(r->headers_in)->elts; - int n = apr_table_elts(r->headers_in)->nelts; - DWORD len = 0; - int i = 0; + int nelts = 2 * apr_table_elts(r->headers_in)->nelts; + int i; - while (i < n * 2) { + for (i = 0; i < nelts; i += 2) len += strlen(raw[i]) + strlen(raw[i + 1]) + 2; - i += 2; - } if (*lpdwSizeofBuffer < len + 1) { + *lpdwSizeofBuffer = len + 1; SetLastError(ERROR_INSUFFICIENT_BUFFER); return FALSE; } - i = 0; - while (i < n * 2) { + for (i = 0; i < nelts; i += 2) { strcpy(lpvBuffer, raw[i]); ((char*)lpvBuffer) += strlen(raw[i]); *(((char*)lpvBuffer)++) = ':'; @@ -630,21 +625,23 @@ BOOL WINAPI GetServerVariable (HCONN hConn, LPSTR lpszVariableName, *lpdwSizeofBuffer = len; return TRUE; } - else { - result = apr_table_get(r->subprocess_env, lpszVariableName); - } + + /* Not a special case */ + result = apr_table_get(r->subprocess_env, lpszVariableName); if (result) { - if (strlen(result) > *lpdwSizeofBuffer) { - *lpdwSizeofBuffer = strlen(result); + len = strlen(result); + if (*lpdwSizeofBuffer < len + 1) { + *lpdwSizeofBuffer = len + 1; SetLastError(ERROR_INSUFFICIENT_BUFFER); return FALSE; } - strncpy(lpvBuffer, result, *lpdwSizeofBuffer); + strcpy(lpvBuffer, result); + *lpdwSizeofBuffer = len; return TRUE; } - /* Didn't find it - should this be ERROR_NO_DATA? */ + /* Not Found */ SetLastError(ERROR_INVALID_INDEX); return FALSE; } @@ -701,34 +698,34 @@ BOOL WINAPI ReadClient (HCONN ConnID, LPVOID lpvBuffer, LPDWORD lpdwSize) } static BOOL SendResponseHeaderEx(isapi_cid *cid, const char *stat, - const char *head, size_t statlen, - size_t headlen) + const char *head, DWORD statlen, + DWORD headlen) { int termarg; char *termch; - if (!stat || !*stat) { + if (!stat || statlen == 0 || !*stat) { stat = "Status: 200 OK"; } else { char *newstat; - if (statlen == 0) - statlen = strlen(stat); - /* Whoops... not NULL terminated */ newstat = apr_palloc(cid->r->pool, statlen + 9); strcpy(newstat, "Status: "); - strncpy(newstat + 8, stat, statlen); + apr_cpystrn(newstat + 8, stat, statlen + 1); stat = newstat; } - if (!head || !*head) { + if (!head || headlen == 0 || !*head) { head = "\r\n"; } - else if ((headlen >= 0) && head[headlen]) { - /* Whoops... not NULL terminated */ - head = apr_pstrndup(cid->r->pool, head, headlen); + else + { + if (head[headlen]) { + /* Whoops... not NULL terminated */ + head = apr_pstrndup(cid->r->pool, head, headlen); + } } - + /* Parse them out, or die trying */ cid->r->status= ap_scan_script_header_err_strs(cid->r, NULL, &termch, &termarg, stat, head, NULL); @@ -794,35 +791,42 @@ BOOL WINAPI ServerSupportFunction (HCONN hConn, DWORD dwHSERequest, return TRUE; case 3: /* HSE_REQ_SEND_RESPONSE_HEADER */ + { /* Parse them out, or die trying */ - return SendResponseHeaderEx(cid, (char*) lpvBuffer, - (char*) lpdwDataType, -1, -1); - + DWORD statlen = 0, headlen = 0; + if (lpvBuffer) + statlen = strlen((char*) lpvBuffer); + if (lpdwDataType) + headlen = strlen((char*) lpdwDataType); + return SendResponseHeaderEx(cid, (char*) lpvBuffer, (char*) lpdwDataType, + statlen, headlen); + } - case HSE_REQ_DONE_WITH_SESSION: - /* Signal to resume the thread completing this request - */ - if (cid->complete) - SetEvent(cid->complete); - return TRUE; + case 4: /* HSE_REQ_DONE_WITH_SESSION */ + /* Signal to resume the thread completing this request + */ + if (cid->complete) + SetEvent(cid->complete); + return TRUE; case 1001: /* HSE_REQ_MAP_URL_TO_PATH */ { /* Map a URL to a filename */ char *file = (char *)lpvBuffer; + DWORD len; subreq = ap_sub_req_lookup_uri(apr_pstrndup(r->pool, file, *lpdwSize), r); - strncpy(file, subreq->filename, *lpdwSize - 1); - file[*lpdwSize - 1] = '\0'; + len = apr_cpystrn(file, subreq->filename, *lpdwSize) - file; + /* IIS puts a trailing slash on directories, Apache doesn't */ if (subreq->finfo.filetype == APR_DIR) { - DWORD l = strlen(file); - if (l < *lpdwSize - 1) { - file[l] = '\\'; - file[l + 1] = '\0'; + if (len < *lpdwSize - 1) { + file[len++] = '\\'; + file[len] = '\0'; } } + *lpdwSize = len; return TRUE; } @@ -912,17 +916,17 @@ BOOL WINAPI ServerSupportFunction (HCONN hConn, DWORD dwHSERequest, char* test_uri = apr_pstrndup(r->pool, (char *)lpvBuffer, *lpdwSize); subreq = ap_sub_req_lookup_uri(test_uri, r); - info->lpszPath[MAX_PATH - 1] = '\0'; - strncpy(info->lpszPath, subreq->filename, MAX_PATH - 1); info->cchMatchingURL = strlen(test_uri); - info->cchMatchingPath = strlen(info->lpszPath); + info->cchMatchingPath = apr_cpystrn(info->lpszPath, subreq->filename, + MAX_PATH) - info->lpszPath; + /* Mapping started with assuming both strings matched. * Now roll on the path_info as a mismatch and handle * terminating slashes for directory matches. */ if (subreq->path_info && *subreq->path_info) { - strncpy(info->lpszPath + info->cchMatchingPath, subreq->path_info, - MAX_PATH - info->cchMatchingPath - 1); + apr_cpystrn(info->lpszPath + info->cchMatchingPath, + subreq->path_info, MAX_PATH - info->cchMatchingPath); info->cchMatchingURL -= strlen(subreq->path_info); if (subreq->finfo.filetype == APR_DIR && info->cchMatchingPath < MAX_PATH - 1) { @@ -1012,8 +1016,7 @@ BOOL WINAPI ServerSupportFunction (HCONN hConn, DWORD dwHSERequest, case 1018: /* HSE_REQ_IS_CONNECTED Added after ISAPI 4.0 */ /* Returns True if client is connected c.f. MSKB Q188346 - * XXX: That statement is very ambigious... assuming the - * identical return mechanism as HSE_REQ_IS_KEEP_CONN. + * assuming the identical return mechanism as HSE_REQ_IS_KEEP_CONN */ *((LPBOOL) lpvBuffer) = (r->connection->aborted == 0); return TRUE; -- 2.50.1