From e208035f3f081a596d08feb25676f002338dc342 Mon Sep 17 00:00:00 2001 From: markt Date: Mon, 23 Nov 2009 00:36:10 +0000 Subject: [PATCH] Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48239 HexUtils exposes public array Based on a patch provided by sebb git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@883201 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/coyote/ajp/AjpAprProcessor.java | 2 +- java/org/apache/coyote/ajp/AjpProcessor.java | 2 +- java/org/apache/coyote/http11/Http11AprProcessor.java | 2 +- java/org/apache/coyote/http11/Http11NioProcessor.java | 2 +- java/org/apache/coyote/http11/Http11Processor.java | 2 +- java/org/apache/coyote/http11/filters/ChunkedInputFilter.java | 4 ++-- .../org/apache/coyote/http11/filters/ChunkedOutputFilter.java | 2 +- java/org/apache/tomcat/util/buf/HexUtils.java | 11 +++++++++-- java/org/apache/tomcat/util/buf/MessageBytes.java | 4 ++-- 9 files changed, 19 insertions(+), 12 deletions(-) diff --git a/java/org/apache/coyote/ajp/AjpAprProcessor.java b/java/org/apache/coyote/ajp/AjpAprProcessor.java index 002f30286..e05b5ecd7 100644 --- a/java/org/apache/coyote/ajp/AjpAprProcessor.java +++ b/java/org/apache/coyote/ajp/AjpAprProcessor.java @@ -920,7 +920,7 @@ public class AjpAprProcessor implements ActionHook { int port = 0; int mult = 1; for (int i = valueL - 1; i > colonPos; i--) { - int charValue = HexUtils.DEC[valueB[i + valueS]]; + int charValue = HexUtils.getDec(valueB[i + valueS]); if (charValue == -1) { // Invalid character error = true; diff --git a/java/org/apache/coyote/ajp/AjpProcessor.java b/java/org/apache/coyote/ajp/AjpProcessor.java index dd5ffaf5e..76e39c9be 100644 --- a/java/org/apache/coyote/ajp/AjpProcessor.java +++ b/java/org/apache/coyote/ajp/AjpProcessor.java @@ -925,7 +925,7 @@ public class AjpProcessor implements ActionHook { int port = 0; int mult = 1; for (int i = valueL - 1; i > colonPos; i--) { - int charValue = HexUtils.DEC[valueB[i + valueS]]; + int charValue = HexUtils.getDec(valueB[i + valueS]); if (charValue == -1) { // Invalid character error = true; diff --git a/java/org/apache/coyote/http11/Http11AprProcessor.java b/java/org/apache/coyote/http11/Http11AprProcessor.java index 51df03842..17b04a4b8 100644 --- a/java/org/apache/coyote/http11/Http11AprProcessor.java +++ b/java/org/apache/coyote/http11/Http11AprProcessor.java @@ -1480,7 +1480,7 @@ public class Http11AprProcessor implements ActionHook { int port = 0; int mult = 1; for (int i = valueL - 1; i > colonPos; i--) { - int charValue = HexUtils.DEC[valueB[i + valueS]]; + int charValue = HexUtils.getDec(valueB[i + valueS]); if (charValue == -1) { // Invalid character error = true; diff --git a/java/org/apache/coyote/http11/Http11NioProcessor.java b/java/org/apache/coyote/http11/Http11NioProcessor.java index d63e76e56..fcf4d94d4 100644 --- a/java/org/apache/coyote/http11/Http11NioProcessor.java +++ b/java/org/apache/coyote/http11/Http11NioProcessor.java @@ -1036,7 +1036,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor implements Actio int port = 0; int mult = 1; for (int i = valueL - 1; i > colonPos; i--) { - int charValue = HexUtils.DEC[valueB[i + valueS]]; + int charValue = HexUtils.getDec(valueB[i + valueS]); if (charValue == -1) { // Invalid character error = true; diff --git a/java/org/apache/coyote/http11/Http11Processor.java b/java/org/apache/coyote/http11/Http11Processor.java index 3be0608db..5b38a5abc 100644 --- a/java/org/apache/coyote/http11/Http11Processor.java +++ b/java/org/apache/coyote/http11/Http11Processor.java @@ -995,7 +995,7 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo int port = 0; int mult = 1; for (int i = valueL - 1; i > colonPos; i--) { - int charValue = HexUtils.DEC[valueB[i + valueS]]; + int charValue = HexUtils.getDec(valueB[i + valueS]); if (charValue == -1) { // Invalid character error = true; diff --git a/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java b/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java index 98e0a0dbf..7e488f26c 100644 --- a/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java +++ b/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java @@ -281,10 +281,10 @@ public class ChunkedInputFilter implements InputFilter { trailer = true; } else if (!trailer) { //don't read data after the trailer - if (HexUtils.DEC[buf[pos]] != -1) { + if (HexUtils.getDec(buf[pos]) != -1) { readDigit = true; result *= 16; - result += HexUtils.DEC[buf[pos]]; + result += HexUtils.getDec(buf[pos]); } else { //we shouldn't allow invalid, non hex characters //in the chunked header diff --git a/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java b/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java index 526c5a75b..e0b18e3bf 100644 --- a/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java +++ b/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java @@ -118,7 +118,7 @@ public class ChunkedOutputFilter implements OutputFilter { while (current > 0) { int digit = current % 16; current = current / 16; - chunkLength[pos--] = HexUtils.HEX[digit]; + chunkLength[pos--] = HexUtils.getHex(digit); } chunkHeader.setBytes(chunkLength, pos + 1, 9 - pos); buffer.doWrite(chunkHeader, res); diff --git a/java/org/apache/tomcat/util/buf/HexUtils.java b/java/org/apache/tomcat/util/buf/HexUtils.java index 568d2d3a7..117c5d3ea 100644 --- a/java/org/apache/tomcat/util/buf/HexUtils.java +++ b/java/org/apache/tomcat/util/buf/HexUtils.java @@ -34,7 +34,7 @@ public final class HexUtils { /** * Table for HEX to DEC byte translation. */ - public static final int[] DEC = { + private static final int[] DEC = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, @@ -57,7 +57,7 @@ public final class HexUtils { /** * Table for DEC to HEX byte translation. */ - public static final byte[] HEX = + private static final byte[] HEX = { (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f' }; @@ -73,4 +73,11 @@ public final class HexUtils { // Nothing to do } + public static int getDec(int index){ + return DEC[index]; + } + + public static byte getHex(int index){ + return HEX[index]; + } } \ No newline at end of file diff --git a/java/org/apache/tomcat/util/buf/MessageBytes.java b/java/org/apache/tomcat/util/buf/MessageBytes.java index aef9abf7f..cccad9b69 100644 --- a/java/org/apache/tomcat/util/buf/MessageBytes.java +++ b/java/org/apache/tomcat/util/buf/MessageBytes.java @@ -526,7 +526,7 @@ public final class MessageBytes implements Cloneable, Serializable { while (current > 0) { int digit = current % 10; current = current / 10; - buf[end++] = HexUtils.HEX[digit]; + buf[end++] = HexUtils.getHex(digit); } byteC.setOffset(0); byteC.setEnd(end); @@ -568,7 +568,7 @@ public final class MessageBytes implements Cloneable, Serializable { while (current > 0) { int digit = (int) (current % 10); current = current / 10; - buf[end++] = HexUtils.HEX[digit]; + buf[end++] = HexUtils.getHex(digit); } byteC.setOffset(0); byteC.setEnd(end); -- 2.11.0