diff options
author | Nick Kralevich <nnk@google.com> | 2013-11-20 10:02:09 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-11-20 10:02:09 -0800 |
commit | a9fa939e2d24748992dd1f7d62f45cb318c2c0a6 (patch) | |
tree | 7fa06fadd737ebd7d67a98fce183b471503d29c9 | |
parent | 738a14cab13e9033f6796a1f4a95b8fb6d8a1032 (diff) | |
parent | 2bc74d1fc6e58dc317e43ce863e257b17dd32b8b (diff) | |
download | cts-android-sdk-4.4.2_r1.0.1.tar.gz |
am 2bc74d1f: am 9885b139: am a962c62c: am 203d5cc5: am 2b62102c: am 4aec0ca7: am 312d6038: am a6355635: Don\'t allow "enable_root" in adb.android-sdk-4.4.2_r1.0.1android-sdk-4.4.2_r1
* commit '2bc74d1fc6e58dc317e43ce863e257b17dd32b8b':
Don't allow "enable_root" in adb.
-rw-r--r-- | tests/tests/security/src/android/security/cts/BannedFilesTest.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/tests/security/src/android/security/cts/BannedFilesTest.java b/tests/tests/security/src/android/security/cts/BannedFilesTest.java index f1db0cbc5ac..eb638a8aa19 100644 --- a/tests/tests/security/src/android/security/cts/BannedFilesTest.java +++ b/tests/tests/security/src/android/security/cts/BannedFilesTest.java @@ -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 { @@ -60,6 +64,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 |