~ubuntu-branches/ubuntu/oneiric/tomcat7/oneiric-security

« back to all changes in this revision

Viewing changes to java/org/apache/coyote/http11/InternalInputBuffer.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2011-09-07 09:45:29 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: package-import@ubuntu.com-20110907094529-cmvfzkvj7d49dhhj
Tags: 7.0.21-1
* New upstream release.
  - Includes fix for CVE-2011-3190.
* Updated my email address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *  See the License for the specific language governing permissions and
15
15
 *  limitations under the License.
16
16
 */
17
 
 
18
 
 
19
17
package org.apache.coyote.http11;
20
18
 
21
19
import java.io.EOFException;
22
20
import java.io.IOException;
 
21
import java.io.InputStream;
 
22
import java.net.Socket;
 
23
import java.nio.charset.Charset;
23
24
 
24
25
import org.apache.coyote.InputBuffer;
25
26
import org.apache.coyote.Request;
 
27
import org.apache.juli.logging.Log;
 
28
import org.apache.juli.logging.LogFactory;
26
29
import org.apache.tomcat.util.buf.ByteChunk;
27
30
import org.apache.tomcat.util.buf.MessageBytes;
 
31
import org.apache.tomcat.util.net.AbstractEndpoint;
 
32
import org.apache.tomcat.util.net.SocketWrapper;
28
33
 
29
34
/**
30
35
 * Implementation of InputBuffer which provides HTTP request header parsing as
32
37
 *
33
38
 * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
34
39
 */
35
 
public class InternalInputBuffer extends AbstractInputBuffer {
 
40
public class InternalInputBuffer extends AbstractInputBuffer<Socket> {
 
41
 
 
42
    private static final Log log = LogFactory.getLog(InternalInputBuffer.class);
 
43
 
 
44
 
 
45
    /**
 
46
     * Underlying input stream.
 
47
     */
 
48
    private InputStream inputStream;
 
49
 
36
50
 
37
51
    /**
38
52
     * Default constructor.
55
69
 
56
70
    }
57
71
 
 
72
    
58
73
    /**
59
74
     * Read the request line. This function is meant to be used during the 
60
75
     * HTTP request header parsing. Do NOT attempt to read the request body 
263
278
     * HTTP header parsing is done
264
279
     */
265
280
    @SuppressWarnings("null") // headerValue cannot be null
266
 
    public boolean parseHeader()
 
281
    private boolean parseHeader()
267
282
        throws IOException {
268
283
 
269
284
        //
316
331
            if (buf[pos] == Constants.COLON) {
317
332
                colon = true;
318
333
                headerValue = headers.addValue(buf, start, pos - start);
 
334
            } else if (!HTTP_TOKEN_CHAR[buf[pos]]) {
 
335
                // If a non-token header is detected, skip the line and
 
336
                // ignore the header
 
337
                skipLine(start);
 
338
                return true;
319
339
            }
 
340
 
320
341
            chr = buf[pos];
321
342
            if ((chr >= Constants.A) && (chr <= Constants.Z)) {
322
343
                buf[pos] = (byte) (chr - Constants.LC_OFFSET);
418
439
    }
419
440
 
420
441
 
 
442
    @Override
 
443
    public void recycle() {
 
444
        super.recycle();
 
445
        inputStream = null;
 
446
    }
 
447
 
 
448
 
421
449
    // ------------------------------------------------------ Protected Methods
422
450
 
423
451
 
 
452
    @Override
 
453
    protected void init(SocketWrapper<Socket> socketWrapper,
 
454
            AbstractEndpoint endpoint) throws IOException {
 
455
        inputStream = socketWrapper.getSocket().getInputStream();
 
456
    }
 
457
 
 
458
 
 
459
 
 
460
    private void skipLine(int start) throws IOException {
 
461
        boolean eol = false;
 
462
        int lastRealByte = start;
 
463
        if (pos - 1 > start) {
 
464
            lastRealByte = pos - 1;
 
465
        }
 
466
        
 
467
        while (!eol) {
 
468
 
 
469
            // Read new bytes if needed
 
470
            if (pos >= lastValid) {
 
471
                if (!fill())
 
472
                    throw new EOFException(sm.getString("iib.eof.error"));
 
473
            }
 
474
 
 
475
            if (buf[pos] == Constants.CR) {
 
476
                // Skip
 
477
            } else if (buf[pos] == Constants.LF) {
 
478
                eol = true;
 
479
            } else {
 
480
                lastRealByte = pos;
 
481
            }
 
482
            pos++;
 
483
        }
 
484
 
 
485
        if (log.isDebugEnabled()) {
 
486
            log.debug(sm.getString("iib.invalidheader", new String(buf, start,
 
487
                    lastRealByte - start + 1, Charset.forName("ISO-8859-1"))));
 
488
        }
 
489
    }
 
490
 
424
491
    /**
425
492
     * Fill the internal buffer using data from the underlying input stream.
426
493
     * 
498
565
            pos = lastValid;
499
566
 
500
567
            return (length);
501
 
 
502
568
        }
503
 
 
504
 
 
505
569
    }
506
 
 
507
 
 
508
570
}