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

Incomplete spec for Mac.update(ByteBuffer input) method. IllegalArgumentException is not in spec.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 7u4
    • security-libs
    • None

      The spec for javax.crypto.Mac.update(ByteBuffer input) method said:
      "
      Processes input.remaining() bytes in the ByteBuffer input, starting at input.position(). Upon return, the buffer's position will be equal to its limit; its limit will not have changed.

      Parameters:
          input - the ByteBuffer
      Throws:
          IllegalStateException - if this Mac has not been initialized.
      "

      Nothing said about what happens if the input is null.

      In that time the IllegalArgumentException will be thrown if pass null pointer:

      public class MacUpdate {
          public static void main(String[] args) {
              try {
                  //Generate secret key
                  KeyGenerator kg = KeyGenerator.getInstance("HmacSHA1");
                  SecretKey key = kg.generateKey();
              
                  //Instantiate Mac
                  Mac theMac = Mac.getInstance("HmacSHA1");
                  theMac.init(key);
                  
                  //do test
                  ByteBuffer buf = null;
                  theMac.update(buf);
                  theMac.doFinal();
              } catch(IllegalArgumentException e){
                  System.out.println(e.toString());//we shouldn'g be here according to spec.
              } catch (Exception e){
                  e.printStackTrace();
              }
          }
      }

      The output will be
      java.lang.IllegalArgumentException: Buffer must not be null

      I guess the spec need to be updated (at least for JDK8).

            wetmore Bradford Wetmore
            afomin Alexander Fomin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: