OLD | NEW |
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import os | 5 import os |
6 | 6 |
7 from autotest_lib.client.bin import test, utils | 7 from autotest_lib.client.bin import test, utils |
8 from autotest_lib.client.common_lib import error | 8 from autotest_lib.client.common_lib import error |
9 | 9 |
10 class platform_StackProtector(test.test): | 10 class platform_StackProtector(test.test): |
(...skipping 23 matching lines...) Expand all Loading... |
34 * stderr containing 'not recognized' on e.g. shell scripts (ok) | 34 * stderr containing 'not recognized' on e.g. shell scripts (ok) |
35 For those, the egrep -q exit(0)'s and there's no output. | 35 For those, the egrep -q exit(0)'s and there's no output. |
36 But, for files compiled without stack protector, the egrep will | 36 But, for files compiled without stack protector, the egrep will |
37 exit(1) and we'll note the name of those files. | 37 exit(1) and we'll note the name of those files. |
38 | 38 |
39 Check all current/future partitions unless known harmless (e.g. proc). | 39 Check all current/future partitions unless known harmless (e.g. proc). |
40 Skip files < 512 bytes due to objdump false positive and test speed. | 40 Skip files < 512 bytes due to objdump false positive and test speed. |
41 """ | 41 """ |
42 libc_glob = "/lib/libc-[0-9]*" | 42 libc_glob = "/lib/libc-[0-9]*" |
43 os.chdir(self.srcdir) | 43 os.chdir(self.srcdir) |
44 cmd = ("find '%s' -wholename /proc -prune -o " | 44 cmd = ("find '%s' -wholename %s -prune -o " |
| 45 " -wholename /proc -prune -o " |
45 " -wholename /dev -prune -o " | 46 " -wholename /dev -prune -o " |
46 " -wholename /sys -prune -o " | 47 " -wholename /sys -prune -o " |
47 " -wholename /home/autotest -prune -o " | |
48 " -wholename /usr/local/autotest -prune -o " | |
49 " -wholename /mnt/stateful_partition -prune -o " | 48 " -wholename /mnt/stateful_partition -prune -o " |
50 # A couple of files known to be a false positive: | 49 # A couple of files known to be a false positive: |
51 " -wholename '/home/chronos/Safe Browsing Bloom*' -prune -o " | 50 " -wholename '/home/chronos/Safe Browsing Bloom*' -prune -o " |
52 # libc needs to be checked differently, skip here: | 51 # libc needs to be checked differently, skip here: |
53 " -wholename '%s' -prune -o " | 52 " -wholename '%s' -prune -o " |
54 " -wholename '/usr/lib/gconv/libCNS.so' -prune -o" | 53 " -wholename '/usr/lib/gconv/libCNS.so' -prune -o" |
55 " -type f -size +511 -exec " | 54 " -type f -size +511 -exec " |
56 "sh -c 'binutils/objdump -CR {} 2>&1 | " | 55 "sh -c 'binutils/objdump -CR {} 2>&1 | " |
57 "egrep -q \"(stack_chk|Invalid|not recognized)\" || echo {}' ';'" | 56 "egrep -q \"(stack_chk|Invalid|not recognized)\" || echo {}' ';'" |
58 ) | 57 ) |
59 badfiles = utils.system_output(cmd % (rootdir, libc_glob)) | 58 badfiles = utils.system_output(cmd % (rootdir, self.autodir, libc_glob)) |
60 | 59 |
61 # special case check for libc, needs different objdump flags | 60 # special case check for libc, needs different objdump flags |
62 cmd = "binutils/objdump -D %s | egrep -q stack_chk || echo %s" | 61 cmd = "binutils/objdump -D %s | egrep -q stack_chk || echo %s" |
63 libc_stack_chk = utils.system_output(cmd % (libc_glob, libc_glob)) | 62 libc_stack_chk = utils.system_output(cmd % (libc_glob, libc_glob)) |
64 | 63 |
65 if badfiles or libc_stack_chk: | 64 if badfiles or libc_stack_chk: |
66 raise error.TestFail("Missing -fstack-protector:\n" | 65 raise error.TestFail("Missing -fstack-protector:\n" |
67 + badfiles + libc_stack_chk) | 66 + badfiles + libc_stack_chk) |
OLD | NEW |