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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 7u4
    • Fix Version/s: None
    • Component/s: security-libs
    • Labels:
      None

      Description

      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).

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: