Skip to content

Commit

Permalink
Fix handling of large ACR lists
Browse files Browse the repository at this point in the history
If an ACR list was split over multiple responses,
AcrListResponse#getAcrListData used BerTlvData#getData to get the array
extra responses after the first should be copied into. However, since
BerTlvData#getData returned a copy of the array and not the actual
array, the copies had no effect.

Fix by implementing BerTlvData#addData, which copies data to the correct
position and increments the index pointer in one go, and adjust
AcrListResponse#getAcrListData to use it.

Also, remove BerTlvData#setCurrentIndex so that the atomic
BerTlvData#addData must be used instead.
  • Loading branch information
megabug authored and martinpaljak committed Jan 9, 2020
1 parent 3067bd5 commit 9b08a1a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions library/src/main/java/pro/javacard/gp/SEAccessControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -602,17 +602,18 @@ public byte[] getData() {
return Arrays.copyOf(data, data.length);
}

public void addData(final byte[] source) {
System.arraycopy(source, 0, data, currentIndex, source.length);
currentIndex += source.length;
}

public int getLength() {
return length;
}

public int getCurrentIndex() {
return currentIndex;
}

public void setCurrentIndex(int index) {
this.currentIndex = index;
}
}

/*
Expand Down Expand Up @@ -662,8 +663,7 @@ public static BerTlvData getAcrListData(final BerTlvData previousData, final byt
System.arraycopy(data, offset, berData, 0, data.length - offset);
return new BerTlvData(berData, length, data.length - offset);
} else if (previousData != null) {
System.arraycopy(data, 0, previousData.getData(), previousData.currentIndex, data.length);
previousData.setCurrentIndex(data.length + previousData.currentIndex);
previousData.addData(data);
return previousData;
} else {
throw new GPDataException("ACR get data : bad response format (GET_DATA)");
Expand Down

0 comments on commit 9b08a1a

Please sign in to comment.