View | Details | Raw Unified | Return to bug 42181
Collapse All | Expand All

(-)java/org/apache/catalina/util/HexUtils.java (-56 lines)
Lines 30-57 Link Here
30
public final class HexUtils {
30
public final class HexUtils {
31
    // Code from Ajp11, from Apache's JServ
31
    // Code from Ajp11, from Apache's JServ
32
32
33
    // Table for HEX to DEC byte translation
34
    public static final int[] DEC = {
35
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
37
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
38
        00, 01, 02, 03, 04, 05, 06, 07,  8,  9, -1, -1, -1, -1, -1, -1,
39
        -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
40
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
41
        -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
42
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
43
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
44
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
45
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
46
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
47
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
48
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
49
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
50
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
51
    };
52
33
53
54
55
    /**
34
    /**
56
     * The string manager for this package.
35
     * The string manager for this package.
57
     */
36
     */
Lines 121-162 Link Here
121
100
122
    }
101
    }
123
102
124
    /**
125
     * Convert 4 hex digits to an int, and return the number of converted
126
     * bytes.
127
     *
128
     * @param hex Byte array containing exactly four hexadecimal digits
129
     *
130
     * @exception IllegalArgumentException if an invalid hexadecimal digit
131
     *  is included
132
     */
133
    public static int convert2Int( byte[] hex ) {
134
        // Code from Ajp11, from Apache's JServ
135
103
136
        // assert b.length==4
137
        // assert valid data
138
        int len;
139
        if(hex.length < 4 ) return 0;
140
        if( DEC[hex[0]]<0 )
141
            throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
142
        len = DEC[hex[0]];
143
        len = len << 4;
144
        if( DEC[hex[1]]<0 )
145
            throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
146
        len += DEC[hex[1]];
147
        len = len << 4;
148
        if( DEC[hex[2]]<0 )
149
            throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
150
        len += DEC[hex[2]];
151
        len = len << 4;
152
        if( DEC[hex[3]]<0 )
153
            throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
154
        len += DEC[hex[3]];
155
        return len;
156
    }
157
158
159
160
    /**
104
    /**
161
     * [Private] Convert the specified value (0 .. 15) to the corresponding
105
     * [Private] Convert the specified value (0 .. 15) to the corresponding
162
     * hexadecimal digit.
106
     * hexadecimal digit.
(-)java/org/apache/coyote/ajp/AjpAprProcessor.java (-2 / +2 lines)
Lines 110-116 Link Here
110
        outputBuffer = ByteBuffer.allocateDirect(packetSize * 2);
110
        outputBuffer = ByteBuffer.allocateDirect(packetSize * 2);
111
111
112
        // Cause loading of HexUtils
112
        // Cause loading of HexUtils
113
        int foo = HexUtils.DEC[0];
113
        HexUtils.getDec('0');
114
114
115
        // Cause loading of HttpMessages
115
        // Cause loading of HttpMessages
116
        HttpMessages.getMessage(200);
116
        HttpMessages.getMessage(200);
Lines 956-962 Link Here
956
            int port = 0;
956
            int port = 0;
957
            int mult = 1;
957
            int mult = 1;
958
            for (int i = valueL - 1; i > colonPos; i--) {
958
            for (int i = valueL - 1; i > colonPos; i--) {
959
                int charValue = HexUtils.DEC[(int) valueB[i + valueS]];
959
                int charValue = HexUtils.getDec(valueB[i + valueS]);
960
                if (charValue == -1) {
960
                if (charValue == -1) {
961
                    // Invalid character
961
                    // Invalid character
962
                    error = true;
962
                    error = true;
(-)java/org/apache/coyote/ajp/AjpProcessor.java (-2 / +2 lines)
Lines 104-110 Link Here
104
                         0, getBodyMessage.getLen());
104
                         0, getBodyMessage.getLen());
105
105
106
        // Cause loading of HexUtils
106
        // Cause loading of HexUtils
107
        int foo = HexUtils.DEC[0];
107
        HexUtils.getDec('0');
108
108
109
        // Cause loading of HttpMessages
109
        // Cause loading of HttpMessages
110
        HttpMessages.getMessage(200);
110
        HttpMessages.getMessage(200);
Lines 961-967 Link Here
961
            int port = 0;
961
            int port = 0;
962
            int mult = 1;
962
            int mult = 1;
963
            for (int i = valueL - 1; i > colonPos; i--) {
963
            for (int i = valueL - 1; i > colonPos; i--) {
964
                int charValue = HexUtils.DEC[(int) valueB[i + valueS]];
964
                int charValue = HexUtils.getDec(valueB[i + valueS]);
965
                if (charValue == -1) {
965
                if (charValue == -1) {
966
                    // Invalid character
966
                    // Invalid character
967
                    error = true;
967
                    error = true;
(-)java/org/apache/coyote/http11/filters/ChunkedInputFilter.java (-2 / +3 lines)
Lines 307-316 Link Here
307
                trailer = true;
307
                trailer = true;
308
            } else if (!trailer) { 
308
            } else if (!trailer) { 
309
                //don't read data after the trailer
309
                //don't read data after the trailer
310
                if (HexUtils.DEC[buf[pos]] != -1) {
310
                int charValue = HexUtils.getDec(buf[pos]);
311
                if (charValue != -1) {
311
                    readDigit = true;
312
                    readDigit = true;
312
                    result *= 16;
313
                    result *= 16;
313
                    result += HexUtils.DEC[buf[pos]];
314
                    result += charValue;
314
                } else {
315
                } else {
315
                    //we shouldn't allow invalid, non hex characters
316
                    //we shouldn't allow invalid, non hex characters
316
                    //in the chunked header
317
                    //in the chunked header
(-)java/org/apache/coyote/http11/Http11AprProcessor.java (-2 / +2 lines)
Lines 107-113 Link Here
107
        initializeFilters();
107
        initializeFilters();
108
108
109
        // Cause loading of HexUtils
109
        // Cause loading of HexUtils
110
        int foo = HexUtils.DEC[0];
110
        HexUtils.getDec('0');
111
    }
111
    }
112
112
113
113
Lines 1535-1541 Link Here
1535
            int port = 0;
1535
            int port = 0;
1536
            int mult = 1;
1536
            int mult = 1;
1537
            for (int i = valueL - 1; i > colonPos; i--) {
1537
            for (int i = valueL - 1; i > colonPos; i--) {
1538
                int charValue = HexUtils.DEC[(int) valueB[i + valueS]];
1538
                int charValue = HexUtils.getDec(valueB[i + valueS]);
1539
                if (charValue == -1) {
1539
                if (charValue == -1) {
1540
                    // Invalid character
1540
                    // Invalid character
1541
                    error = true;
1541
                    error = true;
(-)java/org/apache/coyote/http11/Http11NioProcessor.java (-2 / +2 lines)
Lines 111-117 Link Here
111
        initializeFilters();
111
        initializeFilters();
112
112
113
        // Cause loading of HexUtils
113
        // Cause loading of HexUtils
114
        int foo = HexUtils.DEC[0];
114
        HexUtils.getDec('0');
115
    }
115
    }
116
116
117
117
Lines 1531-1537 Link Here
1531
            int port = 0;
1531
            int port = 0;
1532
            int mult = 1;
1532
            int mult = 1;
1533
            for (int i = valueL - 1; i > colonPos; i--) {
1533
            for (int i = valueL - 1; i > colonPos; i--) {
1534
                int charValue = HexUtils.DEC[(int) valueB[i + valueS]];
1534
                int charValue = HexUtils.getDec(valueB[i + valueS]);
1535
                if (charValue == -1) {
1535
                if (charValue == -1) {
1536
                    // Invalid character
1536
                    // Invalid character
1537
                    error = true;
1537
                    error = true;
(-)java/org/apache/coyote/http11/Http11Processor.java (-2 / +2 lines)
Lines 101-107 Link Here
101
        initializeFilters();
101
        initializeFilters();
102
102
103
        // Cause loading of HexUtils
103
        // Cause loading of HexUtils
104
        int foo = HexUtils.DEC[0];
104
        HexUtils.getDec('0');
105
105
106
    }
106
    }
107
107
Lines 1413-1419 Link Here
1413
            int port = 0;
1413
            int port = 0;
1414
            int mult = 1;
1414
            int mult = 1;
1415
            for (int i = valueL - 1; i > colonPos; i--) {
1415
            for (int i = valueL - 1; i > colonPos; i--) {
1416
                int charValue = HexUtils.DEC[(int) valueB[i + valueS]];
1416
                int charValue = HexUtils.getDec(valueB[i + valueS]);
1417
                if (charValue == -1) {
1417
                if (charValue == -1) {
1418
                    // Invalid character
1418
                    // Invalid character
1419
                    error = true;
1419
                    error = true;
(-)java/org/apache/jk/common/HandlerRequest.java (-1 / +1 lines)
Lines 697-703 Link Here
697
            int port = 0;
697
            int port = 0;
698
            int mult = 1;
698
            int mult = 1;
699
            for (int i = valueL - 1; i > colonPos; i--) {
699
            for (int i = valueL - 1; i > colonPos; i--) {
700
                int charValue = HexUtils.DEC[(int) valueB[i + valueS]];
700
                int charValue = HexUtils.getDec(valueB[i + valueS]);
701
                if (charValue == -1) {
701
                if (charValue == -1) {
702
                    // Invalid character
702
                    // Invalid character
703
                    throw new CharConversionException("Invalid char in port: " + valueB[i + valueS]); 
703
                    throw new CharConversionException("Invalid char in port: " + valueB[i + valueS]); 
(-)java/org/apache/tomcat/util/buf/HexUtils.java (-22 / +19 lines)
Lines 37-59 Link Here
37
    /**
37
    /**
38
     *  Table for HEX to DEC byte translation.
38
     *  Table for HEX to DEC byte translation.
39
     */
39
     */
40
    public static final int[] DEC = {
40
    private static final int[] DEC = {
41
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
42
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
43
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
44
        00, 01, 02, 03, 04, 05, 06, 07,  8,  9, -1, -1, -1, -1, -1, -1,
41
        00, 01, 02, 03, 04, 05, 06, 07,  8,  9, -1, -1, -1, -1, -1, -1,
45
        -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
42
        -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
46
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
43
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
47
        -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
44
        -1, 10, 11, 12, 13, 14, 15,
48
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
49
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
50
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
51
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
52
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
53
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
54
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
55
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
56
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
57
    };
45
    };
58
46
59
47
Lines 75-80 Link Here
75
63
76
    // --------------------------------------------------------- Static Methods
64
    // --------------------------------------------------------- Static Methods
77
65
66
    public static int getDec(int index){
67
        // Fast for correct values, slower for incorrect ones
68
        try {
69
            return DEC[index - '0'];
70
        } catch (ArrayIndexOutOfBoundsException ex) {
71
            return -1;
72
        }
73
    }
78
74
79
    /**
75
    /**
80
     * Convert a String of hexadecimal digits into the corresponding
76
     * Convert a String of hexadecimal digits into the corresponding
Lines 146-151 Link Here
146
     *
142
     *
147
     * @exception IllegalArgumentException if an invalid hexadecimal digit
143
     * @exception IllegalArgumentException if an invalid hexadecimal digit
148
     *  is included
144
     *  is included
145
     * @deprecated Not used, will be removed in Tomcat 7
149
     */
146
     */
150
    public static int convert2Int( byte[] hex ) {
147
    public static int convert2Int( byte[] hex ) {
151
	// Code from Ajp11, from Apache's JServ
148
	// Code from Ajp11, from Apache's JServ
Lines 154-174 Link Here
154
	// assert valid data
151
	// assert valid data
155
	int len;
152
	int len;
156
	if(hex.length < 4 ) return 0;
153
	if(hex.length < 4 ) return 0;
157
	if( DEC[hex[0]]<0 )
154
	if( getDec(hex[0])<0 )
158
	    throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
155
	    throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
159
	len = DEC[hex[0]];
156
	len = getDec(hex[0]);
160
	len = len << 4;
157
	len = len << 4;
161
	if( DEC[hex[1]]<0 )
158
	if( getDec(hex[1])<0 )
162
	    throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
159
	    throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
163
	len += DEC[hex[1]];
160
	len += getDec(hex[1]);
164
	len = len << 4;
161
	len = len << 4;
165
	if( DEC[hex[2]]<0 )
162
	if( getDec(hex[2])<0 )
166
	    throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
163
	    throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
167
	len += DEC[hex[2]];
164
	len += getDec(hex[2]);
168
	len = len << 4;
165
	len = len << 4;
169
	if( DEC[hex[3]]<0 )
166
	if( getDec(hex[3])<0 )
170
	    throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
167
	    throw new IllegalArgumentException(sm.getString("hexUtil.bad"));
171
	len += DEC[hex[3]];
168
	len += getDec(hex[3]);
172
	return len;
169
	return len;
173
    }
170
    }
174
171

Return to bug 42181