Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7106277

Brokenness in the seqNumberOverflow of MAC

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8
    • 7
    • security-libs
    • b14
    • generic, x86
    • generic, windows_xp
    • Not verified

        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.

              xuelei Xuelei Fan
              xuelei Xuelei Fan
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: