[automerger] Add test for disallowing non Binder reads from Binder data in Parcel am: 3ded0bfe12 am: 044cc3da34 am: bf6942658b am: d2c2555c7f am: 0c332c8b7c
Change-Id: Ic3f6a74ade075576b3e8c6b94b38aa8bafca4900
diff --git a/tests/tests/os/src/android/os/cts/ParcelTest.java b/tests/tests/os/src/android/os/cts/ParcelTest.java
index 5b7b187..0663944 100644
--- a/tests/tests/os/src/android/os/cts/ParcelTest.java
+++ b/tests/tests/os/src/android/os/cts/ParcelTest.java
@@ -2951,6 +2951,39 @@
p.recycle();
}
+ public void testBinderDataProtection() {
+ Parcel p;
+ IBinder b = new Binder();
+
+ p = Parcel.obtain();
+ p.writeInt(1);
+ p.writeStrongBinder(b);
+ p.writeInt(2);
+ p.writeStrongBinder(b);
+
+ int finalIntPos = p.dataPosition();
+ p.writeInt(3);
+
+ for (int i = 0; i <= finalIntPos; i++) {
+ p.setDataPosition(i);
+ switch (i) {
+ case 0:
+ assertEquals(1, p.readInt());
+ break;
+ case 28:
+ assertEquals(2, p.readInt());
+ break;
+ case 56:
+ assertEquals(3, p.readInt());
+ break;
+ default:
+ assertEquals(0, p.readInt());
+ }
+ }
+
+ p.recycle();
+ }
+
private class MockClassLoader extends ClassLoader {
public MockClassLoader() {
super();