From c57eb8c6ad462a514f200a94093f94e902959f70 Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Fri, 20 Aug 2021 10:42:52 +0800 Subject: [PATCH] Add null check for the taken callback The requestTetheredInterface() and releaseTetheredInterface() in EthernetManager is annotated as @NonNull. Basically, the taken callback parameter to the service implementation should also be @NonNull. However, it still possible to use native commands to call the method in the aidl. If a null callback is taken, it may cause unexpected results and cause crashes. Add a null check and throw NPE as a warning. Bug: 190058445 Test: adb commands Change-Id: I18fd63aba3f7326597fc3a8c93ba8c9097bf7348 --- .../src/com/android/server/ethernet/EthernetServiceImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/service-t/src/com/android/server/ethernet/EthernetServiceImpl.java b/service-t/src/com/android/server/ethernet/EthernetServiceImpl.java index 3fc6aab758..6b0ce32644 100644 --- a/service-t/src/com/android/server/ethernet/EthernetServiceImpl.java +++ b/service-t/src/com/android/server/ethernet/EthernetServiceImpl.java @@ -35,6 +35,7 @@ import com.android.internal.util.IndentingPrintWriter; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; /** @@ -172,6 +173,7 @@ public class EthernetServiceImpl extends IEthernetManager.Stub { @Override public void requestTetheredInterface(ITetheredInterfaceCallback callback) { + Objects.requireNonNull(callback, "callback must not be null"); NetworkStack.checkNetworkStackPermissionOr(mContext, android.Manifest.permission.NETWORK_SETTINGS); mTracker.requestTetheredInterface(callback); @@ -179,6 +181,7 @@ public class EthernetServiceImpl extends IEthernetManager.Stub { @Override public void releaseTetheredInterface(ITetheredInterfaceCallback callback) { + Objects.requireNonNull(callback, "callback must not be null"); NetworkStack.checkNetworkStackPermissionOr(mContext, android.Manifest.permission.NETWORK_SETTINGS); mTracker.releaseTetheredInterface(callback);