summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author John Johnson <johnrjohn@google.com> 2025-02-11 18:47:32 -0500
committer John Johnson <johnrjohn@google.com> 2025-02-11 21:49:47 -0500
commit8b7c5d8010be585a336fc7f6e2c383a26dc3bdcf (patch)
tree738e9be7074238e4c4438ba60a8970efaae661da
parentd57648f332563e24f9b7db2618cbcda427a4acff (diff)
Verify polling loop patterns and filters in ApduServiceInfo
Test: atest ApduServiceInfoTest Bug: 395728255 Flag: EXEMPT bugfix Change-Id: I3b56289b59684cd71ffaa0fcaf7b5773301381af
-rw-r--r--nfc-non-updatable/java/android/nfc/cardemulation/ApduServiceInfo.java31
1 files changed, 28 insertions, 3 deletions
diff --git a/nfc-non-updatable/java/android/nfc/cardemulation/ApduServiceInfo.java b/nfc-non-updatable/java/android/nfc/cardemulation/ApduServiceInfo.java
index d0de1fc14b0e..f2a68afbfcbe 100644
--- a/nfc-non-updatable/java/android/nfc/cardemulation/ApduServiceInfo.java
+++ b/nfc-non-updatable/java/android/nfc/cardemulation/ApduServiceInfo.java
@@ -70,6 +70,11 @@ import java.util.regex.Pattern;
public final class ApduServiceInfo implements Parcelable {
private static final String TAG = "ApduServiceInfo";
+ private static final Pattern PLPF_PATTERN =
+ Pattern.compile("[0-9A-Fa-f]{2,}[0-9A-Fa-f,\\?,\\*\\.]*");
+ private static final Pattern PLF_PATTERN =
+ Pattern.compile("[0-9A-Fa-f]{2,}");
+
/**
* Component level {@link android.content.pm.PackageManager.Property PackageManager
* .Property} for a system application to change its icon and label
@@ -472,7 +477,12 @@ public final class ApduServiceInfo implements Parcelable {
boolean autoTransact = a.getBoolean(
com.android.internal.R.styleable.PollingLoopFilter_autoTransact,
false);
- if (!mOnHost && !autoTransact) {
+ boolean isValidFilter = PLF_PATTERN.matcher(plf).matches()
+ && plf.length() % 2 == 0;
+ if (!isValidFilter) {
+ Log.e(TAG, "Ignoring polling-loop-filter " + plf
+ + " it is not a valid filter");
+ } else if (!mOnHost && !autoTransact) {
Log.e(TAG, "Ignoring polling-loop-filter " + plf
+ " for offhost service that isn't autoTransact");
} else {
@@ -489,8 +499,12 @@ public final class ApduServiceInfo implements Parcelable {
boolean autoTransact = a.getBoolean(
com.android.internal.R.styleable.PollingLoopFilter_autoTransact,
false);
- if (!mOnHost && !autoTransact) {
- Log.e(TAG, "Ignoring polling-loop-filter " + plf
+ boolean isValidFilter = PLPF_PATTERN.matcher(plf).matches();
+ if (!isValidFilter) {
+ Log.e(TAG, "Ignoring polling-loop-pattern-filter " + plf
+ + " it is not a valid pattern filter");
+ } else if (!mOnHost && !autoTransact) {
+ Log.e(TAG, "Ignoring polling-loop-pattern-filter " + plf
+ " for offhost service that isn't autoTransact");
} else {
mAutoTransactPatterns.put(Pattern.compile(plf), autoTransact);
@@ -814,6 +828,12 @@ public final class ApduServiceInfo implements Parcelable {
@FlaggedApi(Flags.FLAG_NFC_READ_POLLING_LOOP)
public void addPollingLoopFilter(@NonNull String pollingLoopFilter,
boolean autoTransact) {
+ if (!PLF_PATTERN.matcher(pollingLoopFilter).matches()
+ || pollingLoopFilter.length() % 2 != 0) {
+ throw new IllegalArgumentException(
+ "Polling loop filter must contain an even number of characters 0-9 or A-F"
+ );
+ }
if (!mOnHost && !autoTransact) {
return;
}
@@ -842,6 +862,11 @@ public final class ApduServiceInfo implements Parcelable {
@FlaggedApi(Flags.FLAG_NFC_READ_POLLING_LOOP)
public void addPollingLoopPatternFilter(@NonNull String pollingLoopPatternFilter,
boolean autoTransact) {
+ if (!PLPF_PATTERN.matcher(pollingLoopPatternFilter).matches()) {
+ throw new IllegalArgumentException(
+ "Polling loop pattern filter is invalid"
+ );
+ }
if (!mOnHost && !autoTransact) {
return;
}