70
70
public final class ApduServiceInfo implements Parcelable {
71
71
private static final String TAG = "ApduServiceInfo" ;
72
72
73
+ private static final Pattern PLPF_PATTERN =
74
+ Pattern .compile ("[0-9A-Fa-f]{2,}[0-9A-Fa-f,\\ ?,\\ *\\ .]*" );
75
+ private static final Pattern PLF_PATTERN =
76
+ Pattern .compile ("[0-9A-Fa-f]{2,}" );
77
+
73
78
/**
74
79
* Component level {@link android.content.pm.PackageManager.Property PackageManager
75
80
* .Property} for a system application to change its icon and label
@@ -472,7 +477,12 @@ public ApduServiceInfo(@NonNull PackageManager pm, @NonNull ResolveInfo info, bo
472
477
boolean autoTransact = a .getBoolean (
473
478
com .android .internal .R .styleable .PollingLoopFilter_autoTransact ,
474
479
false );
475
- if (!mOnHost && !autoTransact ) {
480
+ boolean isValidFilter = PLF_PATTERN .matcher (plf ).matches ()
481
+ && plf .length () % 2 == 0 ;
482
+ if (!isValidFilter ) {
483
+ Log .e (TAG , "Ignoring polling-loop-filter " + plf
484
+ + " it is not a valid filter" );
485
+ } else if (!mOnHost && !autoTransact ) {
476
486
Log .e (TAG , "Ignoring polling-loop-filter " + plf
477
487
+ " for offhost service that isn't autoTransact" );
478
488
} else {
@@ -489,8 +499,12 @@ public ApduServiceInfo(@NonNull PackageManager pm, @NonNull ResolveInfo info, bo
489
499
boolean autoTransact = a .getBoolean (
490
500
com .android .internal .R .styleable .PollingLoopFilter_autoTransact ,
491
501
false );
492
- if (!mOnHost && !autoTransact ) {
493
- Log .e (TAG , "Ignoring polling-loop-filter " + plf
502
+ boolean isValidFilter = PLPF_PATTERN .matcher (plf ).matches ();
503
+ if (!isValidFilter ) {
504
+ Log .e (TAG , "Ignoring polling-loop-pattern-filter " + plf
505
+ + " it is not a valid pattern filter" );
506
+ } else if (!mOnHost && !autoTransact ) {
507
+ Log .e (TAG , "Ignoring polling-loop-pattern-filter " + plf
494
508
+ " for offhost service that isn't autoTransact" );
495
509
} else {
496
510
mAutoTransactPatterns .put (Pattern .compile (plf ), autoTransact );
@@ -814,6 +828,12 @@ public void setDynamicAidGroup(@NonNull AidGroup aidGroup) {
814
828
@ FlaggedApi (Flags .FLAG_NFC_READ_POLLING_LOOP )
815
829
public void addPollingLoopFilter (@ NonNull String pollingLoopFilter ,
816
830
boolean autoTransact ) {
831
+ if (!PLF_PATTERN .matcher (pollingLoopFilter ).matches ()
832
+ || pollingLoopFilter .length () % 2 != 0 ) {
833
+ throw new IllegalArgumentException (
834
+ "Polling loop filter must contain an even number of characters 0-9 or A-F"
835
+ );
836
+ }
817
837
if (!mOnHost && !autoTransact ) {
818
838
return ;
819
839
}
@@ -842,6 +862,11 @@ public void removePollingLoopFilter(@NonNull String pollingLoopFilter) {
842
862
@ FlaggedApi (Flags .FLAG_NFC_READ_POLLING_LOOP )
843
863
public void addPollingLoopPatternFilter (@ NonNull String pollingLoopPatternFilter ,
844
864
boolean autoTransact ) {
865
+ if (!PLPF_PATTERN .matcher (pollingLoopPatternFilter ).matches ()) {
866
+ throw new IllegalArgumentException (
867
+ "Polling loop pattern filter is invalid"
868
+ );
869
+ }
845
870
if (!mOnHost && !autoTransact ) {
846
871
return ;
847
872
}
0 commit comments