{
request_rec *r = ((isapi_cid *)hConn)->r;
const char *result;
+ DWORD len;
if (!strcmp(lpszVariableName, "ALL_HTTP"))
{
* 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]);
((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)++) = ':';
*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;
}
}
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);
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;
}
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) {
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;
{
request_rec *r = ((isapi_cid *)hConn)->r;
const char *result;
+ DWORD len;
if (!strcmp(lpszVariableName, "ALL_HTTP"))
{
* 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]);
((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)++) = ':';
*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;
}
}
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);
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;
}
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) {
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;