VPN: close the socket in protectVpn() to avoid leaking descriptors.
Change-Id: Idda0c2ea1770abc490566e894711bcb08f60b354
This commit is contained in:
@@ -2528,8 +2528,23 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
* @hide
|
||||
*/
|
||||
@Override
|
||||
public void protectVpn(ParcelFileDescriptor socket) {
|
||||
mVpn.protect(socket, getDefaultInterface());
|
||||
public boolean protectVpn(ParcelFileDescriptor socket) {
|
||||
try {
|
||||
int type = mActiveDefaultNetwork;
|
||||
if (ConnectivityManager.isNetworkTypeValid(type)) {
|
||||
mVpn.protect(socket, mNetTrackers[type].getLinkProperties().getInterfaceName());
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
} finally {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2577,19 +2592,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
return mVpn.getLegacyVpnInfo();
|
||||
}
|
||||
|
||||
private String getDefaultInterface() {
|
||||
if (ConnectivityManager.isNetworkTypeValid(mActiveDefaultNetwork)) {
|
||||
NetworkStateTracker tracker = mNetTrackers[mActiveDefaultNetwork];
|
||||
if (tracker != null) {
|
||||
LinkProperties properties = tracker.getLinkProperties();
|
||||
if (properties != null) {
|
||||
return properties.getInterfaceName();
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("No default interface");
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for VPN subsystem. Currently VPN is not adapted to the service
|
||||
* through NetworkStateTracker since it works differently. For example, it
|
||||
|
||||
Reference in New Issue
Block a user