hgomez 2004/03/12 03:59:32 Modified: jk/native2/common jk_uriMap.c Log: Avoid overflow bug when virtual host is more than 1024 chars.
Provided by Rafal Maczewski Revision Changes Path 1.69 +28 -8 jakarta-tomcat-connectors/jk/native2/common/jk_uriMap.c Index: jk_uriMap.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_uriMap.c,v retrieving revision 1.68 retrieving revision 1.69 diff -u -r1.68 -r1.69 --- jk_uriMap.c 27 Feb 2004 19:10:07 -0000 1.68 +++ jk_uriMap.c 12 Mar 2004 11:59:32 -0000 1.69 @@ -241,29 +241,41 @@ return NULL; } +#define MAX_HOST_LENGTH 1024 + /* Find the vhost */ static jk_uriEnv_t *jk2_uriMap_hostMap(jk_env_t *env, jk_uriMap_t *uriMap, const char *vhost, int port) { int i, j, n; char *name; - char hostname[1024] = {0}; + char hostname[MAX_HOST_LENGTH] = {0}; + char portSuffix[32]; + int vhostLen; if (port) { if (vhost) { - if (strchr(vhost, ':')) - strcpy(hostname, vhost); - else - sprintf(hostname, "%s:%d", vhost, port); + vhostLen = strlen(vhost); + if (strchr(vhost, ':')) { + strncpy(hostname, vhost, MAX_HOST_LENGTH); + } else { + strncpy(hostname, vhost, MAX_HOST_LENGTH); + if (strlen(vhost) < MAX_HOST_LENGTH - 1) { + sprintf(portSuffix,":%d", port); + strncat(hostname+vhostLen, portSuffix, MAX_HOST_LENGTH-vhostLen); + } + } } else sprintf(hostname, "*:%d", port); } else if (vhost) - strcpy(hostname, vhost); + strncpy(hostname, vhost, MAX_HOST_LENGTH); else /* Return default host if vhost and port wasn't suplied */ return uriMap->vhosts->get(env, uriMap->vhosts, "*"); + hostname[MAX_HOST_LENGTH - 1] = 0; + n = uriMap->vhosts->size(env, uriMap->vhosts); /* Check the exact hostname:port first */ for (i = 0 ; i < n ; i++) { @@ -837,13 +849,21 @@ static jk_uriEnv_t *jk2_uriMap_getHostCache(jk_env_t *env, jk_uriMap_t *uriMap, const char *vhost, int port) { - char key[1024]; + char key[MAX_HOST_LENGTH]; + char portSuffix[32]; + int vhostLen; if (!vhost && !port) return uriMap->vhosts->get(env, uriMap->vhosts, "*"); if (!vhost) vhost = "*"; - sprintf(key, "%s:%d", vhost, port); + vhostLen = strlen(vhost); + strncpy(key, vhost, MAX_HOST_LENGTH); + if (vhostLen < MAX_HOST_LENGTH - 1) { + sprintf(portSuffix,":%d", port); + strncat(key+vhostLen, portSuffix, MAX_HOST_LENGTH); + } + key[MAX_HOST_LENGTH - 1] = 0; return uriMap->vhcache->get(env, uriMap->vhcache, key); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]