Author: remy.maucherat(a)jboss.com
Date: 2010-03-17 08:21:39 -0400 (Wed, 17 Mar 2010)
New Revision: 1412
Modified:
trunk/java/org/apache/tomcat/util/buf/B2CConverter.java
trunk/java/org/apache/tomcat/util/buf/C2BConverter.java
trunk/webapps/docs/changelog.xml
Log:
- JBAS-7817: unsafe use of position(). This API is very strict here.
Modified: trunk/java/org/apache/tomcat/util/buf/B2CConverter.java
===================================================================
--- trunk/java/org/apache/tomcat/util/buf/B2CConverter.java 2010-03-16 14:48:04 UTC (rev
1411)
+++ trunk/java/org/apache/tomcat/util/buf/B2CConverter.java 2010-03-17 12:21:39 UTC (rev
1412)
@@ -81,8 +81,8 @@
bb = ByteBuffer.wrap(bc.getBuffer(), bc.getStart(), bc.getLength());
} else {
// Initialize the byte buffer
+ bb.limit(bc.getEnd());
bb.position(bc.getStart());
- bb.limit(bc.getEnd());
}
if ((cb == null) || (cb.array() != cc.getBuffer())) {
// Create a new char buffer if anything changed
@@ -90,8 +90,8 @@
cc.getBuffer().length - cc.getEnd());
} else {
// Initialize the char buffer
+ cb.limit(cc.getBuffer().length);
cb.position(cc.getEnd());
- cb.limit(cc.getBuffer().length);
}
CoderResult result = null;
// Parse leftover if any are present
@@ -126,8 +126,8 @@
cc.setEnd(cb.position());
// Put leftovers in the leftovers byte buffer
if (bc.getLength() > 0) {
+ leftovers.limit(leftovers.array().length);
leftovers.position(bc.getLength());
- leftovers.limit(leftovers.array().length);
bc.substract(leftovers.array(), 0, bc.getLength());
}
}
Modified: trunk/java/org/apache/tomcat/util/buf/C2BConverter.java
===================================================================
--- trunk/java/org/apache/tomcat/util/buf/C2BConverter.java 2010-03-16 14:48:04 UTC (rev
1411)
+++ trunk/java/org/apache/tomcat/util/buf/C2BConverter.java 2010-03-17 12:21:39 UTC (rev
1412)
@@ -75,8 +75,8 @@
bc.getBuffer().length - bc.getEnd());
} else {
// Initialize the byte buffer
+ bb.limit(bc.getBuffer().length);
bb.position(bc.getEnd());
- bb.limit(bc.getBuffer().length);
}
if ((cb == null) || (cb.array() != cc.getBuffer())) {
// Create a new char buffer if anything changed
@@ -84,8 +84,8 @@
cc.getLength());
} else {
// Initialize the char buffer
+ cb.limit(cc.getEnd());
cb.position(cc.getStart());
- cb.limit(cc.getEnd());
}
// Do the decoding and get the results into the byte chunk and the char chunk
CoderResult result = encoder.encode(cb, bb, false);
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2010-03-16 14:48:04 UTC (rev 1411)
+++ trunk/webapps/docs/changelog.xml 2010-03-17 12:21:39 UTC (rev 1412)
@@ -53,6 +53,10 @@
<fix>
<bug>48545</bug>: Optional password on truststores. (markt)
</fix>
+ <fix>
+ <jboss-jira>JBAS-7817</jboss-jira>: Use of position before setting
the limit of a NIO buffer
+ is unsafe. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">
Show replies by date