Commit graph

238 commits

Author SHA1 Message Date
Nick Kralevich
90201d5eca FORTIFY_SOURCE: Add __FD_* checks
Add FORTIFY_SOURCE checks for the following macros:

* FD_CLR
* FD_ISSET
* FD_SET

Bug: 11047121
Change-Id: I3c5952136aec9eff3288b91b1318677ff971525c
2013-10-02 16:11:30 -07:00
Nick Kralevich
944ce989f8 am f7da611b: am 00d51c9f: Merge "Use alloc_size attribute on *alloc functions"
* commit 'f7da611b3dedaf9951e08b0296daf67eda8228c0':
  Use alloc_size attribute on *alloc functions
2013-10-02 14:38:12 -07:00
Nick Kralevich
b91791d71c Use alloc_size attribute on *alloc functions
malloc and family were not declared with __attribute__((alloc_size)).
This was (sometimes) preventing FORTIFY_SOURCE related functions
from knowing the size of the buffer it's dealing with, inhibiting
FORTIFY_SOURCE protections.

Add __attribute__((alloc_size))

Information about the alloc_size attribute can be found
at http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

Change-Id: Ia2f0a445f0170a7325f69259b5e7fb35a9f14921
2013-10-02 14:14:40 -07:00
Christopher Ferris
a59e16bac9 am 34c2a9fc: Move stack unwinding test into library.
* commit '34c2a9fc37848d446bf91ce61783884232fffeb1':
  Move stack unwinding test into library.
2013-09-30 14:46:05 -07:00
Christopher Ferris
427e8cf902 Fix line that got removed by merge.
(cherry picked from commit f14d71fcf7)

Change-Id: Id3dd54d9efd87ef2bbb2c90adae2ce3911695027
2013-09-29 22:14:56 -07:00
Conley Owens
e83a780600 resolved conflicts for merge of f4af9110 to klp-dev-plus-aosp
Change-Id: I9e499e552b758392dd0c7b8d888944c0150dd22a
2013-09-27 13:13:30 -07:00
Nick Kralevich
9a622f874c am cc362291: am 8427b745: Merge "libc: fortify recvfrom()"
* commit 'cc362291362f8183431eccb19267c8a625f36006':
  libc: fortify recvfrom()
2013-09-27 09:11:00 -07:00
Nick Kralevich
8427b7450f Merge "libc: fortify recvfrom()" 2013-09-27 16:05:44 +00:00
Elliott Hughes
fcdb47d7f5 am dbd4dbc0: am a1c1a334: Merge "Add a unit test for %n."
* commit 'dbd4dbc02c969531ff4891c06e66c63ec7a6d75d':
  Add a unit test for %n.
2013-09-25 22:16:18 -07:00
Elliott Hughes
7248a2d4d0 Add a unit test for %n.
Change-Id: I9335e089d66c98d34577f5e1d1a54b8f507b94f6
2013-09-24 18:01:33 -07:00
Nick Kralevich
60f4f9a5b9 libc: fortify recvfrom()
Fortify calls to recv() and recvfrom().

We use __bos0 to match glibc's behavior, and because I haven't
tested using __bos.

Change-Id: Iad6ae96551a89af17a9c347b80cdefcf2020c505
2013-09-24 16:45:01 -07:00
Elliott Hughes
a663ebd468 am f8222078: am 43e5badd: Merge "Fix %hhd formats in the printf family."
* commit 'f82220785d20385fa02aa78b02f3fdb98e5aa553':
  Fix %hhd formats in the printf family.
2013-09-23 16:39:13 -07:00
Elliott Hughes
1d13c64d78 Fix %hhd formats in the printf family.
Found by adapting the simple unit tests for libc logging to test
snprintf too. Fix taken from upstream OpenBSD without updating
the rest of stdio.

Change-Id: Ie339a8e9393a36080147aae4d6665118e5d93647
2013-09-23 16:02:39 -07:00
Christopher Ferris
34c2a9fc37 Move stack unwinding test into library.
Bug: 8291716

(cherry picked from commit 8240bed918)

Change-Id: I1da2d0757ed304c352229f9818c052925d4e976a
2013-09-23 12:16:19 -07:00
Christopher Ferris
f4af911065 Create bionic unit test library for use with CTS.
Bug: 8291716

(cherry picked from commit 153d92765b)

Change-Id: Ia53b85b95621b7000034e4c6259d6586d0987dee
2013-09-23 12:16:01 -07:00
Christopher Ferris
7bfef355b1 Change hard-coded directory.
The tests are using /data/data which is not accessible to a non-root
user. Change this to /data/local/tmp which is accessible to all users.

Bug: 8291716

(cherry picked from commit 5227bb363d)

Change-Id: I83bf70aa8edd21b00321363d7ddcb65a5f048ba5
2013-09-23 12:12:58 -07:00
Christopher Ferris
6d1f85dcdc Change hard-coded temporary directory.
The properties tests creates a temporary directory in /data/nativetest,
but this directory might not exist in all circumstances.
Change this to create the temporary directory in /data/local/tmp.

(cherry picked from commit bd6dc6a886)

Change-Id: I15144ece7ffb5c29eded9a1ef399db630f6af5ab
2013-09-23 12:10:49 -07:00
Christopher Ferris
16e185c908 __memcpy_chk: Fix signed cmp of unsigned values.
I accidentally did a signed comparison of the size_t values passed in
for three of the _chk functions. Changing them to unsigned compares.

Add three new tests to verify this failure is fixed.

Bug: 10691831

Merge from internal master.

(cherry-picked from 883ef2499c)

Change-Id: Id9a96b549435f5d9b61dc132cf1082e0e30889f5
2013-09-20 20:12:09 -07:00
Elliott Hughes
e74f77f92d am 48a909c9: am aad3c52e: Merge "Ensure we have the off64_t variant of every function that takes an off_t."
* commit '48a909c9fd6dbe9be5655ad172d1083fa69c4107':
  Ensure we have the off64_t variant of every function that takes an off_t.
2013-09-19 17:43:01 -07:00
Elliott Hughes
b4f7616fd6 Ensure we have the off64_t variant of every function that takes an off_t.
Change-Id: Ib2eee0cf13162be3b62559b84e90c6dcf5aab1c3
2013-09-19 16:27:24 -07:00
Elliott Hughes
1b75f3e07a am fd5f6f19: am d5ddf40e: Merge "Fix host tests that need the shell."
* commit 'fd5f6f192ab6dcc01091b0e36af822dd3480f9b4':
  Fix host tests that need the shell.
2013-09-19 12:06:44 -07:00
Elliott Hughes
e60c4f0a6c Fix host tests that need the shell.
By making the /system/bin/sh available.

Change-Id: I99200c1ddc922a2f6b5cea8ff2da98aedbe70e7b
2013-09-19 11:28:20 -07:00
Elliott Hughes
ca0f0662f4 am 2443358b: am 4a509d89: Merge "Add bionic-unit-tests-run-on-host special target"
* commit '2443358b3717bdce932303bbcbe625f59e1ae380':
  Add bionic-unit-tests-run-on-host special target
2013-09-18 19:20:31 -07:00
Pavel Chupin
f22fb68751 Add bionic-unit-tests-run-on-host special target
Allows running the tests linked with bionic .so on the host if host and
target are compatible. See more comments and usage limitation inlined.

make bionic-unit-tests-run-on-host should do build and run.

Change-Id: I5946fa72e009d324baa9da18f460294b3c1a615e
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2013-09-18 19:09:24 -07:00
Christopher Ferris
2e7a8b44c2 resolved conflicts for merge of 883ef249 to klp-dev-plus-aosp
Change-Id: I1e2bd03a0cb5a0ab191c525d1574377bc7fd90ab
2013-09-10 19:49:04 -07:00
Christopher Ferris
883ef2499c __memcpy_chk: Fix signed cmp of unsigned values.
I accidentally did a signed comparison of the size_t values passed in
for three of the _chk functions. Changing them to unsigned compares.

Add three new tests to verify this failure is fixed.

Bug: 10691831
Change-Id: Ia831071f7dffd5972a748d888dd506c7cc7ddba3
2013-09-10 17:34:03 -07:00
Christopher Ferris
7a80982913 am fc24bc25: am 99b859cf: Merge "Move stack unwinding test into library."
* commit 'fc24bc2544edad03798a1c69d6a76259e6f1e7dd':
  Move stack unwinding test into library.
2013-08-29 14:18:41 -07:00
Christopher Ferris
8240bed918 Move stack unwinding test into library.
Bug: 8291716
Change-Id: Ia270f074b574a8fe86b5ad435bdef80999c64295
2013-08-29 14:00:25 -07:00
Nick Kralevich
2c87c3ff02 am cfd0d72d: am eb8f3622: Merge "FORTIFY_SOURCE: introduce __strncpy_chk2"
* commit 'cfd0d72da8641087f9c4015ee586614da9f7320a':
  FORTIFY_SOURCE: introduce __strncpy_chk2
2013-08-28 13:07:57 -07:00
Nick Kralevich
93501d3ab8 FORTIFY_SOURCE: introduce __strncpy_chk2
This change detects programs reading beyond the end of "src" when
calling strncpy.

Change-Id: Ie1b42de923385d62552b22c27b2d4713ab77ee03
2013-08-28 12:39:06 -07:00
Christopher Ferris
7c8ebaf6c1 am d923b307: am 2557433d: Merge "Change hard-coded directory."
* commit 'd923b3075c9cf9e0749cee7373cabb9afba9420c':
  Change hard-coded directory.
2013-08-27 17:41:17 -07:00
Christopher Ferris
3825da5c07 am 7a2c2784: am 1f216e30: Merge "Create bionic unit test library for use with CTS."
* commit '7a2c2784a656adfae613b6b53d388988d6f2efa6':
  Create bionic unit test library for use with CTS.
2013-08-27 17:22:37 -07:00
Christopher Ferris
5227bb363d Change hard-coded directory.
The tests are using /data/data which is not accessible to a non-root
user. Change this to /data/local/tmp which is accessible to all users.

Bug: 8291716

Change-Id: I66476bbbaf5d1dc0c103863abf9219405f06a85b
2013-08-27 17:22:34 -07:00
Christopher Ferris
153d92765b Create bionic unit test library for use with CTS.
Bug: 8291716

Change-Id: I46b749348456fae7892eecca6b44aef51a0e4747
2013-08-27 14:35:56 -07:00
Jeff Hao
e9e10c13ff Fix pthread_getcpuclockid.
clock_gettime was returning EINVAL for the values
produced by pthread_getcpuclockid.

Bug: 10346183

(cherry picked from commit 9b06cc3c1b)

Change-Id: Ib81a7024c218a4502f256c3002b9030e2aaa278d
2013-08-26 14:04:16 -07:00
Elliott Hughes
6b5eb3134a am e5ac43e1: am c44205cf: Merge "Work around tzcode\'s reliance on signed overflow."
* commit 'e5ac43e19afe270c2a70e4fb5d02b4cf056d50d7':
  Work around tzcode's reliance on signed overflow.
2013-08-22 12:27:52 -07:00
Elliott Hughes
f0c10a4a16 Work around tzcode's reliance on signed overflow.
I've mailed the tz list about this, and will switch to whatever upstream
fix comes along as soon as it's available.

Bug: 10310929

(cherry picked from commit 7843d44a59)

Change-Id: I205e2440703444c50cecd91d3458d33613ddbc59
2013-08-22 12:23:47 -07:00
Elliott Hughes
7843d44a59 Work around tzcode's reliance on signed overflow.
I've mailed the tz list about this, and will switch to whatever upstream
fix comes along as soon as it's available.

Bug: 10310929
Change-Id: I36bf3fcf11f5ac9b88137597bac3487a7bb81b0f
2013-08-22 12:21:18 -07:00
Christopher Ferris
2389a26705 am c058154b: am c8039337: Merge "Change hard-coded temporary directory."
* commit 'c058154b747f295c98ad771d3dec4065749ee1a9':
  Change hard-coded temporary directory.
2013-08-16 12:25:58 -07:00
Elliott Hughes
e714eb157e am 6b6aaec8: am 4eacb341: Merge "Fix pthread_getcpuclockid."
* commit '6b6aaec892b1f256787fbbf106449f7d7e5888a2':
  Fix pthread_getcpuclockid.
2013-08-16 12:25:58 -07:00
Christopher Ferris
c8039337e3 Merge "Change hard-coded temporary directory." 2013-08-16 03:13:42 +00:00
Jeff Hao
9b06cc3c1b Fix pthread_getcpuclockid.
clock_gettime was returning EINVAL for the values
produced by pthread_getcpuclockid.

Bug: 10346183
Change-Id: Iabe643d7d46110bb311a0367aa0fc737f653208e
2013-08-15 15:34:22 -07:00
Christopher Ferris
bd6dc6a886 Change hard-coded temporary directory.
The properties tests creates a temporary directory in /data/nativetest,
but this directory might not exist in all circumstances.
Change this to create the temporary directory in /data/local/tmp.

Change-Id: I812d3e24fcd084c5d74055c9faa95b1656f255bc
2013-08-15 12:54:40 -07:00
Elliott Hughes
840a114eb1 Add futimens.
(cherry picked from commit d0be7c8f9a)

Bug: 10239370
Change-Id: I0087e85a94d83b6ce68ec6a0768c44cbe4bd0132
2013-08-08 17:52:06 -07:00
Elliott Hughes
d0be7c8f9a Add futimens.
Bug: 10239370
Change-Id: I518340084103dc339ef8a065d4837d6258a1381d
2013-08-08 17:13:33 -07:00
Elliott Hughes
49b24b4efb am 3287dccf: Merge "Add ssse3 implementation of __memcmp16."
* commit '3287dccf2ecced89bb39b857abc8eba997bc3f51':
  Add ssse3 implementation of __memcmp16.
2013-08-02 18:04:01 -07:00
Alexander Ivchenko
baa91f4f89 Add ssse3 implementation of __memcmp16.
__memcmp16 was missing in x86. Also added C-version for backward
compatibility. Added bionic test for __memcmp16 and for wmemcmp.

Change-Id: I33718441e7ee343cdb021d91dbeaf9ce2d4d7eb4
Signed-off-by: Alexander Ivchenko <alexander.ivchenko@intel.com>
2013-08-02 17:57:23 -07:00
Elliott Hughes
993ea1061b am 5148661f: am 67750c85: Merge "Fix pthread_getattr_np, pthread_attr_setguardsize, and pthread_attr_setstacksize."
* commit '5148661f8d2be514d0e3c191bc1e489157ae1154':
  Fix pthread_getattr_np, pthread_attr_setguardsize, and pthread_attr_setstacksize.
2013-07-15 16:45:54 -07:00
Elliott Hughes
b95cf0d23a Fix pthread_getattr_np, pthread_attr_setguardsize, and pthread_attr_setstacksize.
pthread_getattr_np was reporting the values supplied to us, not the values we
actually used, which is kinda the whole point of pthread_getattr_np.

pthread_attr_setguardsize and pthread_attr_setstacksize were reporting EINVAL
for any size that wasn't a multiple of the system page size. This is
unnecessary. We can just round like POSIX suggests and glibc already does.

Also improve the error reporting for pthread_create failures.

Change-Id: I7ebc518628a8a1161ec72e111def911d500bba71
2013-07-15 14:51:07 -07:00
Elliott Hughes
d3522051ce am 7e56f462: am 3db1f359: Merge "Add a trivial gmtime(3) test."
* commit '7e56f462ad19791d7b270e297fc994d18df43252':
  Add a trivial gmtime(3) test.
2013-07-12 14:35:19 -07:00
Elliott Hughes
ee178bfb79 Add a trivial gmtime(3) test.
Change-Id: I849f200a455cd6971646fa45766ab22ba19fb866
2013-07-12 11:25:20 -07:00
Elliott Hughes
1087e0df4f am 731f7c2d: am 9d476716: Merge "Add <sys/statvfs.h>."
* commit '731f7c2d0e531d5e0ecdd771d743053f8d093e16':
  Add <sys/statvfs.h>.
2013-07-11 10:16:32 -07:00
Elliott Hughes
06040fd75c Add <sys/statvfs.h>.
Bug: 2512019
Change-Id: I6e7fd3fa281977cc4bc270481a95416b5b2dc351
2013-07-09 13:25:03 -07:00
Elliott Hughes
742aad3584 am 7c808b29: am feec97a7: Merge "Fix inttypes.h PRI?PTR and SCN?PTR macros."
* commit '7c808b29d5cea61e5bda90a1b0f2f0e669ee135e':
  Fix inttypes.h PRI?PTR and SCN?PTR macros.
2013-07-02 15:50:36 -07:00
Elliott Hughes
74f0833df6 Fix inttypes.h PRI?PTR and SCN?PTR macros.
Our intptr_t and uintptr_t aren't "long". Add a compilation test so we remember
to fix this to cope with 32- and 64-bit later.

Bug: http://code.google.com/p/android/issues/detail?id=57218
Change-Id: I2f816d339edb4f7d57e4418b818fb4c602093f38
2013-07-02 15:35:27 -07:00
Nick Kralevich
4b17283c98 am 28d298a6: am 413eef71: Merge "More FORTIFY_SOURCE functions under clang"
* commit '28d298a673da4367f27f428db5e12d7dad3d8e83':
  More FORTIFY_SOURCE functions under clang
2013-07-01 10:04:18 -07:00
Nick Kralevich
a6cde39276 More FORTIFY_SOURCE functions under clang
* bzero
* umask
* strlcat

Change-Id: I65065208e0b8b37e10f6a266d5305de8fa9e59fc
2013-06-29 08:16:22 -07:00
Nick Kralevich
fda0c06605 am 2018cfa8: am 394df35e: Merge "Reorganize FORTIFY_SOURCE tests."
* commit '2018cfa85d4c7f36316376f5b090be5f0d3d13dc':
  Reorganize FORTIFY_SOURCE tests.
2013-06-28 13:15:39 -07:00
Nick Kralevich
5bcf39842e Reorganize FORTIFY_SOURCE tests.
Get rid of a lot of the duplication in the various FORTIFY_SOURCE
tests. Instead, we build 4 separate static libraries, with
4 different compile time options, and link them into the final test
binary.

Change-Id: Idb0b7cccc8dd837adb037bf4ddfe8942ae138230
2013-06-28 11:54:29 -07:00
Nick Kralevich
9a268a10bb am f9ef0106: am 78a7bf99: Merge "stdio.h: enable vs?printf clang FORTIFY_SOURCE"
* commit 'f9ef0106da43d21e6cb68d87b86d806f63b215fd':
  stdio.h: enable vs?printf clang FORTIFY_SOURCE
2013-06-27 10:18:17 -07:00
Nick Kralevich
c8ae8bd941 stdio.h: enable vs?printf clang FORTIFY_SOURCE
Enable FORTIFY_SOURCE protections under clang for the following
functions:

  * vsprintf
  * vsnprintf

and add unittests.

Change-Id: I90f8a27f7b202c78b5dd8ebf53050bf9e33496f7
2013-06-27 09:17:48 -07:00
Elliott Hughes
d9643a3119 am d31287d6: am 7d624e9a: Merge "Kernel dso support for \'dl_iterate_phdr\' function"
* commit 'd31287d6017475209cfee2fea0532bdc8c0f4aac':
  Kernel dso support for 'dl_iterate_phdr' function
2013-06-25 17:01:47 -07:00
Nick Kralevich
caad18c7d1 am 71802135: am bfacb603: Merge "libc: enable FORTIFY_SOURCE snprintf under clang"
* commit '7180213557f3120b391053b4f5861037eda6ebb6':
  libc: enable FORTIFY_SOURCE snprintf under clang
2013-06-25 16:30:53 -07:00
Greg Hackmann
be30c7a78a bionic: revert to a single (larger) property area
d329697 is too complicated.  Change the multiple property pages back to
a single 128K property area that's mapped in entirely at initialization
(the memory will not get allocated until the pages are touched).

d329697 has other changes useful for testing (moving property area
initialization inside bionic and adding __system_property_set_filename)
so undo the change manually rather than with git revert.

Change-Id: Icd137669a4f8bc248e9dd2c1e8cc54e9193c9a6d
Signed-off-by: Greg Hackmann <ghackmann@google.com>
2013-06-25 13:34:32 -07:00
Greg Hackmann
d5276422ca bionic: add hierarchical properties test
Deliberately put items several levels deep in the trie hierarchy to test
the trie traversal

Change-Id: I995a1cdd3b5e74162fb5d25bc0f65140bdf2f719
Signed-off-by: Greg Hackmann <ghackmann@google.com>
2013-06-25 13:34:29 -07:00
Sergey Melnikov
c45087bffa Kernel dso support for 'dl_iterate_phdr' function
Kernel provides virtual DSO for stack unwinding/exception handlind info for
signal usage case. Stack unwinding routines use 'dl_iterate_phdr' function
for additional DWARF info gathering from DSOs. Patch enables virtual DSO
enumeration via dl_iterate_phdr function.

Signed-off-by: Sergey Melnikov <sergey.melnikov@intel.com>
Change-Id: Ic2882b28f40b456a088bc1e63c50cbfda7e4a102
2013-06-25 13:12:39 -07:00
Nick Kralevich
621b19dddb libc: enable FORTIFY_SOURCE snprintf under clang
Change-Id: I8b8059782a720104722b0841994b38f873ed02aa
2013-06-25 10:02:35 -07:00
Nick Kralevich
5f7f7fca27 am 95448039: am 0ea1d5c0: Merge "libc: enable sprintf FORTIFY_SOURCE under clang"
* commit '954480393f4539f62cdc3f6cb83c562050ea4f51':
  libc: enable sprintf FORTIFY_SOURCE under clang
2013-06-25 05:59:32 -07:00
Greg Hackmann
890aa0d937 Revert "bionic: add hierarchical properties test"
This reverts commit 0f76e2340c.
2013-06-24 18:05:18 -07:00
Greg Hackmann
fa8cc0629f Revert "bionic: revert to a single (larger) property area"
This reverts commit 5f05348c18.
2013-06-24 18:05:16 -07:00
Greg Hackmann
1540f601be bionic: revert to a single (larger) property area
d329697 is too complicated.  Change the multiple property pages back to
a single 128K property area that's mapped in entirely at initialization
(the memory will not get allocated until the pages are touched).

d329697 has other changes useful for testing (moving property area
initialization inside bionic and adding __system_property_set_filename)
so undo the change manually rather than with git revert.

Signed-off-by: Greg Hackmann <ghackmann@google.com>

(cherry picked from commit 5f05348c18)

Change-Id: I690704552afc07a4dd410277893ca9c40bc13e5f
2013-06-24 16:35:37 -07:00
Greg Hackmann
cb215a7e9e bionic: make property area expandable
The property area is initially one 4K region, automatically expanding as
needed up to 64 regions.

To avoid duplicating code, __system_property_area_init() now allocates
and initializes the first region (previously it was allocated in init's
init_property_area() and initialized in bionic).  For testing purposes,
__system_property_set_filename() may be used to override the file used
to map in regions.

Signed-off-by: Greg Hackmann <ghackmann@google.com>

(cherry picked from commit d32969701b)

Change-Id: I038d451fe8849b0c4863663eec6f57f6521bf4a7
2013-06-24 16:35:15 -07:00
Greg Hackmann
5f05348c18 bionic: revert to a single (larger) property area
d329697 is too complicated.  Change the multiple property pages back to
a single 128K property area that's mapped in entirely at initialization
(the memory will not get allocated until the pages are touched).

d329697 has other changes useful for testing (moving property area
initialization inside bionic and adding __system_property_set_filename)
so undo the change manually rather than with git revert.

Change-Id: I0ecb27843404f93af5489f15bfe657d65175e4f0
Signed-off-by: Greg Hackmann <ghackmann@google.com>
2013-06-24 16:15:52 -07:00
Nick Kralevich
c6eb985454 libc: enable sprintf FORTIFY_SOURCE under clang
clang doesn't support __builtin_va_arg_pack(), so we have
to use #define instead.

Change-Id: I2ee75e6267d60cdf997fee6b9b0547bf68f062a1
2013-06-24 14:10:29 -07:00
Greg Hackmann
0f76e2340c bionic: add hierarchical properties test
Deliberately put items several levels deep in the trie hierarchy to test
the trie traversal

Change-Id: Id3cbd2e7d3500216b1ac8025eac70c0939622903
Signed-off-by: Greg Hackmann <ghackmann@google.com>
2013-06-24 13:14:10 -07:00
Nick Kralevich
33ae76abf3 am 5fed0eea: am 0ce28d20: Merge "libc: enable FORTIFY_SOURCE clang strlcpy"
* commit '5fed0eeabd88bfe241c416f2c2f44a14b6e447fa':
  libc: enable FORTIFY_SOURCE clang strlcpy
2013-06-20 12:34:11 -07:00
Nick Kralevich
8bafa7452e libc: enable FORTIFY_SOURCE clang strlcpy
Change-Id: Idcfe08f5afc3dde592416df9eba83f64e130c7c2
2013-06-20 12:17:44 -07:00
Greg Hackmann
d32969701b bionic: make property area expandable
The property area is initially one 4K region, automatically expanding as
needed up to 64 regions.

To avoid duplicating code, __system_property_area_init() now allocates
and initializes the first region (previously it was allocated in init's
init_property_area() and initialized in bionic).  For testing purposes,
__system_property_set_filename() may be used to override the file used
to map in regions.

Change-Id: Ibe00ef52464bfa590953c4699a6d98383b0142b1
Signed-off-by: Greg Hackmann <ghackmann@google.com>
2013-06-19 11:02:15 -07:00
Nick Kralevich
02ca0e3142 Merge "Fix FORTIFY_SOURCE unittests." 2013-06-19 17:33:57 +00:00
Nick Kralevich
3cd4cac2ce Fix FORTIFY_SOURCE unittests.
The compiler is too damn smart.

Change-Id: Ibef3ef41ec99f8cd9c06f1dbca535819f9a08197
2013-06-19 10:25:44 -07:00
Greg Hackmann
c6ff844d75 bionic: add __system_property_foreach
find_nth() will be inefficient on a trie.  Since find_nth() is only used
internally and only for enumerating properties, we can add a foreach()
function to do this directly.

Signed-off-by: Greg Hackmann <ghackmann@google.com>

(cherry picked from commit 577418403d)

Change-Id: Iaca97d1182ce2c28863ba85241cbb5cf6185eb2f
2013-06-18 19:24:29 -07:00
Nick Kralevich
dd0880fec3 Merge "libc: add limited FORTIFY_SOURCE support for clang" 2013-06-18 20:23:49 +00:00
Colin Cross
7d06813d93 bionic: fix deleting property arrays in property benchmark
Use delete[] to delete arrays allocated with new []

Change-Id: Icc2a6b23df09049c008f7f1f50ed93a277174308
2013-06-18 13:08:28 -07:00
Colin Cross
7d90cfa6b5 bionic: change properties benchmarks to read a single property
The properties benchmarks were reading n properties from a property
area with n properties in it, which was making it hard to compare
the time between runs of different sizes.  Change the benchmark
to read a random property per iteration so the numbers between
runs are comparable.

Change-Id: Ib1648ce0948d9038fce76d209608427376cfb8da
2013-06-18 12:55:52 -07:00
Nick Kralevich
16d1af167f libc: add limited FORTIFY_SOURCE support for clang
In 829c089f83, we disabled all
FORTIFY_SOURCE support when compiling under clang. At the time,
we didn't have proper test cases, and couldn't easily create targeted
clang tests.

This change re-enables FORTIFY_SOURCE support under clang for a
limited set of functions, where we have explicit unittests available.
The functions are:

* memcpy
* memmove
* strcpy
* strncpy
* strcat
* strncat
* memset
* strlen (with modifications)
* strchr (with modifications)
* strrchr (with modifications)

It may be possible, in the future, to enable other functions. However,
I need to write unittests first.

For strlen, strchr, and strrchr, clang unconditionally calls the
fortified version of the relevant function. If it doesn't know the
size of the buffer it's dealing with, it passes in ((size_t) -1),
which is the largest possible size_t.

I added two new clang specific unittest files, primarily copied
from fortify?_test.cpp.

I've also rebuild the entire system with these changes, and didn't
observe any obvious problems.

Change-Id: If12a15089bb0ffe93824b485290d05b14355fcaa
2013-06-18 12:14:20 -07:00
Colin Cross
b27e200ad6 bionic: add tests for properties
(cherry picked from commit 37d9f75dde)

Change-Id: Iac00ce10a4272032a1cbdbc4204277d6876e3365
2013-06-17 16:58:47 -07:00
msg555
0f020d18b1 Handles spurious wake-ups in pthread_join()
Removed 'join_count' from pthread_internal_t and switched to using the flag
PTHREAD_ATTR_FLAG_JOINED to indicate if a thread is being joined. Combined with
a switch to a while loop in pthread_join, this fixes spurious wake-ups but
prevents a thread from being joined multiple times. This is fine for
two reasons:

1) The pthread_join specification allows for undefined behavior when multiple
   threads try to join a single thread.

2) There is no thread safe way to allow multiple threads to join a single
   thread with the pthread interface.  The second thread calling pthread_join
   could be pre-empted until the thread is destroyed and its handle reused for
   a different thread.  Therefore multi-join is always an error.

Bug: https://code.google.com/p/android/issues/detail?id=52255
Change-Id: I8b6784d47620ffdcdbfb14524e7402e21d46c5f7
2013-06-12 17:30:58 -07:00
Nick Kralevich
fd0325bd98 fix unittests.
7e6ce1a3c5 fixed abort() to raise
SIGABRT rather than causing SIGSEGV. However, the unittests were
not updated.

Fix unittests.

Change-Id: I73db194127b9b9e9440358aa94273863765a736b
2013-06-11 15:45:23 -07:00
Christopher Ferris
885f3b9cad Implement malloc_usable_size for debug impls.
- Implemented chk_memalign.
- Fixed a few bugs in leak_memalign.
- Implemented {leak,fill,check,qemu}_malloc_usable_size.
- Make malloc_usable_size update at run time.
- Add malloc_test.cpp as a small set of tests for the
  malloc debug routines.
- Fix the qemu routines since it's been broken since it moved to C++.
- Add support for the %u format to the out_vformat in libc_logging.cpp.
  This is used by the emulator code.

Tested using the bionic-unit-tests with setprop libc.debug.malloc
set to 1, 5, and 10.

I tested as much as possible on the emulator, but tracing doesn't appear
to be working properly.

Bug: 6143477

Merge change from internal master.

(cherry-picked from commit 3d594c2580)

Change-Id: I4ae00fffba82315a8c283f35893fd554460722fb
2013-06-07 14:55:32 -07:00
Nick Kralevich
13476deec4 Add tests for __strcpy_chk()
Change-Id: I5675d04fcd471732c1b87b83879a54fbcd27762e
2013-06-04 11:55:08 -07:00
Nick Kralevich
cf870199d5 FORTIFY_SOURCE: strcat / strncat optimize
__strcat_chk and __strncat_chk are slightly inefficient,
because they end up traversing over the same memory region
two times.

This change optimizes __strcat_chk / __strncat_chk so they
only access the memory once. Although I haven't benchmarked these
changes, it should improve the performance of these functions.

__strlen_chk - expose this function, even if -D_FORTIFY_SOURCE
isn't defined. This is needed to compile libc itself without
-D_FORTIFY_SOURCE.

Change-Id: Id2c70dff55a276b47c59db27a03734d659f84b74
2013-05-31 09:07:46 -07:00
Nick Kralevich
8cc145edf4 Add strncpy FORTIFY_SOURCE tests.
Change-Id: Id108b1d72b44d7e5fb911268e80bbdf896808f60
2013-05-30 13:21:14 -07:00
Nick Kralevich
4f40e511b0 libc: cleanup strchr
Move strchr to a .cpp file, and change to bionic directory.

Change-Id: I64ade7df326c0a9a714aca4caf5647b6833b1c97
2013-05-02 13:58:03 -07:00
Nick Kralevich
277226bf43 keep test names consistent with other tests.
Change-Id: I23dc4d963af40406b270af83cd17f6c8c95f1de3
2013-05-01 15:05:01 -07:00
Nick Kralevich
80541922e3 add strrchr -D_FORTIFY_SOURCE=2 test.
Change-Id: I1b95bb0086ae9f2f506f3cc90cee834c0ce3b1d8
2013-05-01 14:55:33 -07:00
Nick Kralevich
78d6d9888c libc: upgrade sprintf to _FORTIFY_SOURCE=2
Upgrade sprintf to fortify_source level 2, to catch
additional security bugs.

Change-Id: Ibc957d65e4cb96152de84b3745a04e00fa22659e
2013-04-29 16:41:54 -07:00
Nick Kralevich
1aae9bd170 strncpy: implement _FORTIFY_SOURCE=2
Add support for fortify source level 2 to strncpy.
This will enable detection of more areas where strncpy
is used inappropriately. For example, this would have detected
bug 8727221.

Move the fortify_source tests out of string_test.cpp, and
put it into fortify1_test.cpp.

Create a new fortify2_test.cpp file, which copies all
the tests in fortify1_test.cpp, and adds fortify_source level
2 specific tests.

Change-Id: Ica0fba531cc7d0609e4f23b8176739b13f7f7a83
2013-04-29 15:22:10 -07:00
Elliott Hughes
0b25f633a2 Switch to current FreeBSD qsort.
Change-Id: Ic46cd0b663dc5fa78c99dd38db0bfe849a25e789
2013-04-11 18:08:34 -07:00
Elliott Hughes
6b05c8e280 Start moving to current FreeBSD stdio.
This only touches the easy stuff.

Change-Id: Iecee57f1681dba5c56bff59f0e9a89811a71f0ca
2013-04-11 13:55:01 -07:00
Kito Cheng
8baa929d5d Prevent name conflict for eventfd.cpp and eventfd.s when building libc.a
- eventfd.cpp and eventfd.s will output to the same file when building libc.a
   out/target/product/*/obj/STATIC_LIBRARIES/libc_intermediates/WHOLE/libc_common_objs/eventfd.o
 - And then `eventfd` will undefined when statically linked to libc.

Also add a unit test.

Change-Id: Ib310ade3256712ca617a90539e8eb07459c98505
2013-04-03 11:10:37 -07:00