Merge "Validate commands and arguments." into ics-mr0

This commit is contained in:
Jeff Sharkey
2011-10-17 15:29:25 -07:00
committed by Android (Google) Code Review
2 changed files with 19 additions and 1 deletions

View File

@@ -207,6 +207,13 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo
*/ */
private void sendCommandLocked(String command, String argument) private void sendCommandLocked(String command, String argument)
throws NativeDaemonConnectorException { throws NativeDaemonConnectorException {
if (command != null && command.indexOf('\0') >= 0) {
throw new IllegalArgumentException("unexpected command: " + command);
}
if (argument != null && argument.indexOf('\0') >= 0) {
throw new IllegalArgumentException("unexpected argument: " + argument);
}
if (LOCAL_LOGD) Slog.d(TAG, String.format("SND -> {%s} {%s}", command, argument)); if (LOCAL_LOGD) Slog.d(TAG, String.format("SND -> {%s} {%s}", command, argument));
if (mOutputStream == null) { if (mOutputStream == null) {
Slog.e(TAG, "No connection to daemon", new IllegalStateException()); Slog.e(TAG, "No connection to daemon", new IllegalStateException());

View File

@@ -16,6 +16,8 @@
package com.android.server; package com.android.server;
import static android.Manifest.permission.ACCESS_NETWORK_STATE;
import static android.Manifest.permission.CHANGE_NETWORK_STATE;
import static android.Manifest.permission.DUMP; import static android.Manifest.permission.DUMP;
import static android.Manifest.permission.MANAGE_NETWORK_POLICY; import static android.Manifest.permission.MANAGE_NETWORK_POLICY;
import static android.net.NetworkStats.SET_DEFAULT; import static android.net.NetworkStats.SET_DEFAULT;
@@ -350,6 +352,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
} }
public InterfaceConfiguration getInterfaceConfig(String iface) throws IllegalStateException { public InterfaceConfiguration getInterfaceConfig(String iface) throws IllegalStateException {
mContext.enforceCallingOrSelfPermission(ACCESS_NETWORK_STATE, TAG);
String rsp; String rsp;
try { try {
rsp = mConnector.doCommand("interface getcfg " + iface).get(0); rsp = mConnector.doCommand("interface getcfg " + iface).get(0);
@@ -404,6 +407,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
public void setInterfaceConfig( public void setInterfaceConfig(
String iface, InterfaceConfiguration cfg) throws IllegalStateException { String iface, InterfaceConfiguration cfg) throws IllegalStateException {
mContext.enforceCallingOrSelfPermission(CHANGE_NETWORK_STATE, TAG);
LinkAddress linkAddr = cfg.addr; LinkAddress linkAddr = cfg.addr;
if (linkAddr == null || linkAddr.getAddress() == null) { if (linkAddr == null || linkAddr.getAddress() == null) {
throw new IllegalStateException("Null LinkAddress given"); throw new IllegalStateException("Null LinkAddress given");
@@ -421,6 +425,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
} }
public void setInterfaceDown(String iface) throws IllegalStateException { public void setInterfaceDown(String iface) throws IllegalStateException {
mContext.enforceCallingOrSelfPermission(CHANGE_NETWORK_STATE, TAG);
try { try {
InterfaceConfiguration ifcg = getInterfaceConfig(iface); InterfaceConfiguration ifcg = getInterfaceConfig(iface);
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("up", "down"); ifcg.interfaceFlags = ifcg.interfaceFlags.replace("up", "down");
@@ -432,6 +437,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
} }
public void setInterfaceUp(String iface) throws IllegalStateException { public void setInterfaceUp(String iface) throws IllegalStateException {
mContext.enforceCallingOrSelfPermission(CHANGE_NETWORK_STATE, TAG);
try { try {
InterfaceConfiguration ifcg = getInterfaceConfig(iface); InterfaceConfiguration ifcg = getInterfaceConfig(iface);
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up"); ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
@@ -444,6 +450,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
public void setInterfaceIpv6PrivacyExtensions(String iface, boolean enable) public void setInterfaceIpv6PrivacyExtensions(String iface, boolean enable)
throws IllegalStateException { throws IllegalStateException {
mContext.enforceCallingOrSelfPermission(CHANGE_NETWORK_STATE, TAG);
String cmd = String.format("interface ipv6privacyextensions %s %s", iface, String cmd = String.format("interface ipv6privacyextensions %s %s", iface,
enable ? "enable" : "disable"); enable ? "enable" : "disable");
try { try {
@@ -459,6 +466,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
/* TODO: This is right now a IPv4 only function. Works for wifi which loses its /* TODO: This is right now a IPv4 only function. Works for wifi which loses its
IPv6 addresses on interface down, but we need to do full clean up here */ IPv6 addresses on interface down, but we need to do full clean up here */
public void clearInterfaceAddresses(String iface) throws IllegalStateException { public void clearInterfaceAddresses(String iface) throws IllegalStateException {
mContext.enforceCallingOrSelfPermission(CHANGE_NETWORK_STATE, TAG);
String cmd = String.format("interface clearaddrs %s", iface); String cmd = String.format("interface clearaddrs %s", iface);
try { try {
mConnector.doCommand(cmd); mConnector.doCommand(cmd);
@@ -491,10 +499,12 @@ public class NetworkManagementService extends INetworkManagementService.Stub
} }
public void addRoute(String interfaceName, RouteInfo route) { public void addRoute(String interfaceName, RouteInfo route) {
mContext.enforceCallingOrSelfPermission(CHANGE_NETWORK_STATE, TAG);
modifyRoute(interfaceName, ADD, route); modifyRoute(interfaceName, ADD, route);
} }
public void removeRoute(String interfaceName, RouteInfo route) { public void removeRoute(String interfaceName, RouteInfo route) {
mContext.enforceCallingOrSelfPermission(CHANGE_NETWORK_STATE, TAG);
modifyRoute(interfaceName, REMOVE, route); modifyRoute(interfaceName, REMOVE, route);
} }
@@ -578,6 +588,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
} }
public RouteInfo[] getRoutes(String interfaceName) { public RouteInfo[] getRoutes(String interfaceName) {
mContext.enforceCallingOrSelfPermission(ACCESS_NETWORK_STATE, TAG);
ArrayList<RouteInfo> routes = new ArrayList<RouteInfo>(); ArrayList<RouteInfo> routes = new ArrayList<RouteInfo>();
// v4 routes listed as: // v4 routes listed as: