prevent nullptr dereference when calling unwanted

When the EthernetNetworkAgent has already been stopped, a call to
unwanted will cause a crash due to a nullptr derefernce.

Bug: 197279734
Test: atest EthernetNetworkFactoryTest
Change-Id: Ice39c603bdd3e3139aa8ece7fb897bf7b567e74b
This commit is contained in:
Patrick Rohr
2021-08-20 07:56:26 +02:00
parent 698b59510f
commit 4cf6809d75

View File

@@ -506,12 +506,15 @@ public class EthernetNetworkFactory extends NetworkFactory {
mNetworkFactory.getProvider(), new EthernetNetworkAgent.Callbacks() {
@Override
public void onNetworkUnwanted() {
// if mNetworkAgent is null, we have already called stop.
if (mNetworkAgent == null) return;
if (this == mNetworkAgent.getCallbacks()) {
stop();
} else if (mNetworkAgent != null) {
} else {
Log.d(TAG, "Ignoring unwanted as we have a more modern " +
"instance");
} // Otherwise, we've already called stop.
}
}
});
mNetworkAgent.register();