Add null check for clientInfo

If the binder death notification for a INsdManagerCallback was
received before any calls are received by NsdService, the
clientInfo would be cleared and cause NPE. Thus, add a null check
to prevent crash.

Bug: 241741274
Test: atest FrameworksNetTests
Change-Id: Iebe761cd579bf3ee46ead389620bed60a21e3154
This commit is contained in:
Paul Hu
2022-08-16 07:21:55 +00:00
parent dd2eca9e4a
commit 116b4c0b6b
2 changed files with 51 additions and 0 deletions

View File

@@ -295,6 +295,13 @@ public class NsdService extends INsdManager.Stub {
if (DBG) Log.d(TAG, "Discover services");
args = (ListenerArgs) msg.obj;
clientInfo = mClients.get(args.connector);
// If the binder death notification for a INsdManagerCallback was received
// before any calls are received by NsdService, the clientInfo would be
// cleared and cause NPE. Add a null check here to prevent this corner case.
if (clientInfo == null) {
Log.e(TAG, "Unknown connector in discovery");
break;
}
if (requestLimitReached(clientInfo)) {
clientInfo.onDiscoverServicesFailed(
@@ -321,6 +328,13 @@ public class NsdService extends INsdManager.Stub {
if (DBG) Log.d(TAG, "Stop service discovery");
args = (ListenerArgs) msg.obj;
clientInfo = mClients.get(args.connector);
// If the binder death notification for a INsdManagerCallback was received
// before any calls are received by NsdService, the clientInfo would be
// cleared and cause NPE. Add a null check here to prevent this corner case.
if (clientInfo == null) {
Log.e(TAG, "Unknown connector in stop discovery");
break;
}
try {
id = clientInfo.mClientIds.get(clientId);
@@ -341,6 +355,14 @@ public class NsdService extends INsdManager.Stub {
if (DBG) Log.d(TAG, "Register service");
args = (ListenerArgs) msg.obj;
clientInfo = mClients.get(args.connector);
// If the binder death notification for a INsdManagerCallback was received
// before any calls are received by NsdService, the clientInfo would be
// cleared and cause NPE. Add a null check here to prevent this corner case.
if (clientInfo == null) {
Log.e(TAG, "Unknown connector in registration");
break;
}
if (requestLimitReached(clientInfo)) {
clientInfo.onRegisterServiceFailed(
clientId, NsdManager.FAILURE_MAX_LIMIT);
@@ -363,6 +385,9 @@ public class NsdService extends INsdManager.Stub {
if (DBG) Log.d(TAG, "unregister service");
args = (ListenerArgs) msg.obj;
clientInfo = mClients.get(args.connector);
// If the binder death notification for a INsdManagerCallback was received
// before any calls are received by NsdService, the clientInfo would be
// cleared and cause NPE. Add a null check here to prevent this corner case.
if (clientInfo == null) {
Log.e(TAG, "Unknown connector in unregistration");
break;
@@ -380,6 +405,13 @@ public class NsdService extends INsdManager.Stub {
if (DBG) Log.d(TAG, "Resolve service");
args = (ListenerArgs) msg.obj;
clientInfo = mClients.get(args.connector);
// If the binder death notification for a INsdManagerCallback was received
// before any calls are received by NsdService, the clientInfo would be
// cleared and cause NPE. Add a null check here to prevent this corner case.
if (clientInfo == null) {
Log.e(TAG, "Unknown connector in resolution");
break;
}
if (clientInfo.mResolvedService != null) {
clientInfo.onResolveServiceFailed(