-
Bug
-
Resolution: Fixed
-
P3
-
7
-
b14
-
generic, x86
-
generic, windows_xp
-
Not verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2216476 | 7u4 | Xuelei Fan | P3 | Closed | Fixed | b02 |
What's wrong with this code in MAC.java?
final boolean seqNumOverflow() {
/*
* Conservatively, we don't allow more records to be generated
* when there are only 2^8 sequence numbers left.
*/
return (block != null && mac != null &&
block[0] == 0xFF && block[1] == 0xFF &&
block[2] == 0xFF && block[3] == 0xFF &&
block[4] == 0xFF && block[5] == 0xFF &&
block[6] == 0xFF);
}
If it's not obvious to you, then run the following:
public class Main {
public static void main(String[] args) throws Exception {
byte [] ba = new byte[] { -1 };
System.out.println((ba[0] == (byte) 0xFF ? "true" : "false"));
System.out.println((ba[0] == 0xFF ? "true" : "false"));
}
}
In first println, both of these are bytes, and the compared. In the second, 0xFF is an int, so ba[0] is widened to -1 (0xffffffff), and thus 0xff == 0xffffffff is false.
final boolean seqNumOverflow() {
/*
* Conservatively, we don't allow more records to be generated
* when there are only 2^8 sequence numbers left.
*/
return (block != null && mac != null &&
block[0] == 0xFF && block[1] == 0xFF &&
block[2] == 0xFF && block[3] == 0xFF &&
block[4] == 0xFF && block[5] == 0xFF &&
block[6] == 0xFF);
}
If it's not obvious to you, then run the following:
public class Main {
public static void main(String[] args) throws Exception {
byte [] ba = new byte[] { -1 };
System.out.println((ba[0] == (byte) 0xFF ? "true" : "false"));
System.out.println((ba[0] == 0xFF ? "true" : "false"));
}
}
In first println, both of these are bytes, and the compared. In the second, 0xFF is an int, so ba[0] is widened to -1 (0xffffffff), and thus 0xff == 0xffffffff is false.
- backported by
-
JDK-2216476 Brokenness in the seqNumberOverflow of MAC
-
- Closed
-
- duplicates
-
JDK-7166661 Inproper compare of sequence number in sun.security.ssl.MAC class
-
- Closed
-