From: timw Date: Thu, 23 Sep 2010 10:38:56 +0000 (+0000) Subject: https://issues.apache.org/bugzilla/show_bug.cgi?id=49102 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=15eee8f1cfee2888c9995626b4e61e759b58bc45;p=tomcat7.0 https://issues.apache.org/bugzilla/show_bug.cgi?id=49102 Protecting AJP code -> header/method lookup arrays with getters. No measurable slowdown (especially after a profiling JIT gets done with it). git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1000400 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/coyote/ajp/AjpAprProcessor.java b/java/org/apache/coyote/ajp/AjpAprProcessor.java index 48f92e19d..c0c3c0750 100644 --- a/java/org/apache/coyote/ajp/AjpAprProcessor.java +++ b/java/org/apache/coyote/ajp/AjpAprProcessor.java @@ -713,7 +713,7 @@ public class AjpAprProcessor implements ActionHook { // Translate the HTTP method code to a String. byte methodCode = requestHeaderMessage.getByte(); if (methodCode != Constants.SC_M_JK_STORED) { - String methodName = Constants.methodTransArray[methodCode - 1]; + String methodName = Constants.getMethodForCode(methodCode - 1); request.method().setString(methodName); } @@ -747,7 +747,7 @@ public class AjpAprProcessor implements ActionHook { isc &= 0xFF00; if(0xA000 == isc) { requestHeaderMessage.getInt(); // To advance the read position - hName = Constants.headerTransArray[hId - 1]; + hName = Constants.getHeaderForCode(hId - 1); vMB = headers.addValue(hName); } else { // reset hId -- if the header currently being read diff --git a/java/org/apache/coyote/ajp/AjpProcessor.java b/java/org/apache/coyote/ajp/AjpProcessor.java index c7c45ba57..f6097c000 100644 --- a/java/org/apache/coyote/ajp/AjpProcessor.java +++ b/java/org/apache/coyote/ajp/AjpProcessor.java @@ -719,7 +719,7 @@ public class AjpProcessor implements ActionHook { // Translate the HTTP method code to a String. byte methodCode = requestHeaderMessage.getByte(); if (methodCode != Constants.SC_M_JK_STORED) { - String methodName = Constants.methodTransArray[methodCode - 1]; + String methodName = Constants.getMethodForCode(methodCode - 1); request.method().setString(methodName); } @@ -753,7 +753,7 @@ public class AjpProcessor implements ActionHook { isc &= 0xFF00; if(0xA000 == isc) { requestHeaderMessage.getInt(); // To advance the read position - hName = Constants.headerTransArray[hId - 1]; + hName = Constants.getHeaderForCode(hId - 1); vMB = headers.addValue(hName); } else { // reset hId -- if the header currently being read diff --git a/java/org/apache/coyote/ajp/Constants.java b/java/org/apache/coyote/ajp/Constants.java index 007fec9c5..b2e6b81af 100644 --- a/java/org/apache/coyote/ajp/Constants.java +++ b/java/org/apache/coyote/ajp/Constants.java @@ -120,7 +120,7 @@ public final class Constants { public static final int MAX_SEND_SIZE = MAX_PACKET_SIZE - SEND_HEAD_LEN; // Translates integer codes to names of HTTP methods - public static final String []methodTransArray = { + private static final String [] methodTransArray = { "OPTIONS", "GET", "HEAD", @@ -149,6 +149,16 @@ public final class Constants { "BASELINE-CONTROL", "MKACTIVITY" }; + + /** + * Converts an AJP coded HTTP method to the method name. + * @param code the coded value + * @return the string value of the method + */ + public static final String getMethodForCode(final int code) { + return methodTransArray[code]; + } + public static final int SC_M_JK_STORED = (byte) 0xFF; // id's for common request headers @@ -170,7 +180,7 @@ public final class Constants { public static final byte SC_A_SSL_KEY_SIZE = 11; // XXX ??? // Translates integer codes to request header names - public static final String []headerTransArray = { + private static final String [] headerTransArray = { "accept", "accept-charset", "accept-encoding", @@ -187,8 +197,17 @@ public final class Constants { "user-agent" }; + /** + * Converts an AJP coded HTTP request header to the header name. + * @param code the coded value + * @return the string value of the header name + */ + public static final String getHeaderForCode(final int code) { + return headerTransArray[code]; + } + // Translates integer codes to response header names - public static final String []responseTransArray = { + private static final String [] responseTransArray = { "Content-Type", "Content-Language", "Content-Length", @@ -201,6 +220,15 @@ public final class Constants { "Status", "WWW-Authenticate" }; + + /** + * Converts an AJP coded response header name to the HTTP response header name. + * @param code the coded value + * @return the string value of the header + */ + public static final String getResponseHeaderForCode(final int code) { + return responseTransArray[code]; + } private static final Hashtable responseTransHash = new Hashtable(20); @@ -209,7 +237,7 @@ public final class Constants { try { int i; for (i = 0; i < SC_RESP_AJP13_MAX; i++) { - responseTransHash.put(responseTransArray[i], + responseTransHash.put(getResponseHeaderForCode(i), new Integer(0xA001 + i)); } }