VPN: close the socket in protectVpn() to avoid leaking descriptors.

Change-Id: Idda0c2ea1770abc490566e894711bcb08f60b354
This commit is contained in:
Chia-chi Yeh
2011-07-14 16:19:19 -07:00
parent dc5d1badd0
commit 9e4ff6ef91
2 changed files with 18 additions and 16 deletions

View File

@@ -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