From 8aff5bda80c112cc3a758239cb90ddc459b8c673 Mon Sep 17 00:00:00 2001 From: Ivan Gerasimov Date: Mon, 17 Feb 2020 16:32:05 -0800 Subject: [PATCH] 8163251: Hard coded loop limit prevents reading of smart card data greater than 8k Reviewed-by: valeriep, rriggs --- .../classes/sun/security/smartcardio/ChannelImpl.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/java.smartcardio/share/classes/sun/security/smartcardio/ChannelImpl.java b/src/java.smartcardio/share/classes/sun/security/smartcardio/ChannelImpl.java index adfd39ed4cf..5e8f5e3a083 100644 --- a/src/java.smartcardio/share/classes/sun/security/smartcardio/ChannelImpl.java +++ b/src/java.smartcardio/share/classes/sun/security/smartcardio/ChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2020, 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 @@ -150,6 +150,7 @@ final class ChannelImpl extends CardChannel { return res; } + private final static int RESPONSE_ITERATIONS = 256; private final static byte[] B0 = new byte[0]; private byte[] doTransmit(byte[] command) throws CardException { @@ -182,8 +183,9 @@ final class ChannelImpl extends CardChannel { int k = 0; byte[] result = B0; while (true) { - if (++k >= 32) { - throw new CardException("Could not obtain response"); + if (++k > RESPONSE_ITERATIONS) { + throw new CardException("Number of response iterations" + + " exceeded maximum " + RESPONSE_ITERATIONS); } byte[] response = SCardTransmit (card.cardId, card.protocol, command, 0, n);