< prev index next >
src/java.smartcardio/share/classes/sun/security/smartcardio/ChannelImpl.java
Print this page
rev 51511 : imported patch 6474858-CardChannel-transmit-CommandAPDU-throws-unexpected-ArrayIndexOutOfBoundsException
@@ -1,7 +1,7 @@
/*
- * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -186,11 +186,11 @@
throw new CardException("Could not obtain response");
}
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
command[n - 1] = response[1];
continue;
@@ -199,18 +199,22 @@
// Issue a GET RESPONSE command with the same CLA
// using SW2 as short Le field
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;
command[4] = response[rn - 1];
n = 5;
continue;
}
-
}
result = concat(result, response, rn);
break;
}
return result;
< prev index next >