changeset 52271:2418b305aa01

6474858: CardChannel.transmit(CommandAPDU) throws unexpected ArrayIndexOutOfBoundsException Reviewed-by: valeriep
author igerasim
date Fri, 24 Aug 2018 18:56:41 -0700
parents dda0f219dafa
children a716460217ed
files src/java.smartcardio/share/classes/sun/security/smartcardio/ChannelImpl.java test/jdk/sun/security/smartcardio/TestTransmit.java
diffstat 2 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.smartcardio/share/classes/sun/security/smartcardio/ChannelImpl.java	Thu Aug 23 21:16:45 2018 -0700
+++ b/src/java.smartcardio/share/classes/sun/security/smartcardio/ChannelImpl.java	Fri Aug 24 18:56:41 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -188,7 +188,7 @@
                 byte[] response = SCardTransmit
                     (card.cardId, card.protocol, command, 0, n);
                 int rn = response.length;
-                if (getresponse && (rn >= 2)) {
+                if (getresponse && (rn >= 2) && (n >= 1)) {
                     // see ISO 7816/2005, 5.1.3
                     if ((rn == 2) && (response[0] == 0x6c)) {
                         // Resend command using SW2 as short Le field
@@ -201,6 +201,11 @@
                         if (rn > 2) {
                             result = concat(result, response, rn - 2);
                         }
+                        if (command.length < 5) {
+                            byte cla = command[0];
+                            command = new byte[5];
+                            command[0] = cla;
+                        }
                         command[1] = (byte)0xC0;
                         command[2] = 0;
                         command[3] = 0;
@@ -208,7 +213,6 @@
                         n = 5;
                         continue;
                     }
-
                 }
                 result = concat(result, response, rn);
                 break;
--- a/test/jdk/sun/security/smartcardio/TestTransmit.java	Thu Aug 23 21:16:45 2018 -0700
+++ b/test/jdk/sun/security/smartcardio/TestTransmit.java	Fri Aug 24 18:56:41 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 6293769 6294527
+ * @bug 6293769 6294527 6474858
  * @summary test transmit() works
  * @author Andreas Sterbenz
  * @modules java.smartcardio/javax.smartcardio
@@ -90,6 +90,13 @@
             } // else ignore
         }
 
+        // JDK-6474858 : CardChannel.transmit(CommandAPDU) throws
+        //               unexpected ArrayIndexOutOfBoundsException
+        {
+            CommandAPDU capdu2 = new CommandAPDU(0x00, 0xA4, 0x00, 0x00);
+            channel.transmit(capdu2);
+        }
+
         // disconnect
         card.disconnect(true);