Merge "Add logs for target uids and duration to destroyLiveTcpSockets"
diff --git a/staticlibs/device/com/android/net/module/util/netlink/NetlinkUtils.java b/staticlibs/device/com/android/net/module/util/netlink/NetlinkUtils.java
index 308ea24..b512a95 100644
--- a/staticlibs/device/com/android/net/module/util/netlink/NetlinkUtils.java
+++ b/staticlibs/device/com/android/net/module/util/netlink/NetlinkUtils.java
@@ -93,6 +93,15 @@
if (nlmsghdr == null || nlmsghdr.nlmsg_type != NetlinkConstants.NLMSG_ERROR) {
return null;
}
+
+ final int messageLength = NetlinkConstants.alignedLengthOf(nlmsghdr.nlmsg_len);
+ final int payloadLength = messageLength - StructNlMsgHdr.STRUCT_SIZE;
+ if (payloadLength < 0 || payloadLength > bytes.remaining()) {
+ // Malformed message or runt buffer. Pretend the buffer was consumed.
+ bytes.position(bytes.limit());
+ return null;
+ }
+
return NetlinkErrorMessage.parse(nlmsghdr, bytes);
}
diff --git a/staticlibs/native/bpf_headers/include/bpf/KernelUtils.h b/staticlibs/native/bpf_headers/include/bpf/KernelUtils.h
index b3dd86c..769ec4b 100644
--- a/staticlibs/native/bpf_headers/include/bpf/KernelUtils.h
+++ b/staticlibs/native/bpf_headers/include/bpf/KernelUtils.h
@@ -119,7 +119,11 @@
}
static constexpr bool isArm() {
-#if defined(__arm__) || defined(__aarch64__)
+#if defined(__arm__)
+ static_assert(isUserspace32bit(), "huh? arm must be 32 bit");
+ return true;
+#elif defined(__aarch64__)
+ static_assert(isUserspace64bit(), "aarch64 must be LP64 - no support for ILP32");
return true;
#else
return false;
@@ -127,7 +131,11 @@
}
static constexpr bool isX86() {
-#if defined(__i386__) || defined(__x86_64__)
+#if defined(__i386__)
+ static_assert(isUserspace32bit(), "huh? i386 must be 32 bit");
+ return true;
+#elif defined(__x86_64__)
+ static_assert(isUserspace64bit(), "x86_64 must be LP64 - no support for ILP32 (x32)");
return true;
#else
return false;
diff --git a/staticlibs/tests/unit/src/com/android/testutils/TestableNetworkCallbackTest.kt b/staticlibs/tests/unit/src/com/android/testutils/TestableNetworkCallbackTest.kt
index 4ed881a..e838bdc 100644
--- a/staticlibs/tests/unit/src/com/android/testutils/TestableNetworkCallbackTest.kt
+++ b/staticlibs/tests/unit/src/com/android/testutils/TestableNetworkCallbackTest.kt
@@ -354,6 +354,13 @@
}
@Test
+ fun testExpectClass() {
+ val net = Network(1)
+ mCallback.onAvailable(net)
+ assertFails { mCallback.expect(LOST, net) }
+ }
+
+ @Test
fun testPoll() {
assertNull(mCallback.poll(SHORT_TIMEOUT_MS))
TNCInterpreter.interpretTestSpec(initial = mCallback, lineShift = 1,
diff --git a/staticlibs/testutils/devicetests/com/android/testutils/TestableNetworkCallback.kt b/staticlibs/testutils/devicetests/com/android/testutils/TestableNetworkCallback.kt
index 0e73112..4b6aea2 100644
--- a/staticlibs/testutils/devicetests/com/android/testutils/TestableNetworkCallback.kt
+++ b/staticlibs/testutils/devicetests/com/android/testutils/TestableNetworkCallback.kt
@@ -236,7 +236,11 @@
errorMsg: String? = null,
test: (T) -> Boolean = { true }
) = expect<CallbackEntry>(network, timeoutMs, errorMsg) {
- test(it as? T ?: fail("Expected callback ${type.simpleName}, got $it"))
+ if (type.isInstance(it)) {
+ test(it as T) // Cast can't fail since type.isInstance(it) and type: KClass<T>
+ } else {
+ fail("Expected callback ${type.simpleName}, got $it")
+ }
} as T
@JvmOverloads