Commit 4aec0ca7 authored by Nick Kralevich's avatar Nick Kralevich Committed by Android Git Automerger
Browse files

am 312d6038: am a6355635: Don\'t allow "enable_root" in adb.

* commit '312d6038':
  Don't allow "enable_root" in adb.
parents bb4f7277 312d6038
......@@ -20,7 +20,11 @@ import android.os.cts.FileUtils;
import junit.framework.TestCase;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
public class BannedFilesTest extends TestCase {
......@@ -48,6 +52,34 @@ public class BannedFilesTest extends TestCase {
}
}
public void testNoEnableRoot() throws UnsupportedEncodingException {
byte[] badPattern = "enable_root".getBytes("US-ASCII");
assertFileDoesNotContain("/system/bin/adb", badPattern);
}
private static void assertFileDoesNotContain(String filename, byte[] pattern) {
try {
File f = new File(filename);
byte[] fileData = new byte[(int) f.length()];
DataInputStream dis = new DataInputStream(new FileInputStream(f));
dis.readFully(fileData);
dis.close();
outer:
for (int i = 0; i < (fileData.length - pattern.length); i++) {
for (int j = 0; j < pattern.length; j++) {
if (fileData[i+j] != pattern[j]) {
continue outer;
}
}
fail("Found banned pattern in " + filename);
}
} catch (IOException e) {
// ignore - no such file, or IO error. Assume OK.
}
}
/**
* setuid or setgid "ip" command can be used to modify the
* routing tables of a device, potentially allowing a malicious
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment