aboutsummaryrefslogtreecommitdiffstats
path: root/tests/string_test.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fix over read in strcpy/stpcpy/strcat.Christopher Ferris2015-10-291-3/+17
| | | | | | | | | | | | | | | | | | | | | | | This bug will happen when these circumstances are met: - Destination address & 0x7 == 1, strlen of src is 11, 12, 13. - Destination address & 0x7 == 2, strlen of src is 10, 11, 12. - Destination address & 0x7 == 3, strlen of src is 9, 10, 11. - Destination address & 0x7 == 4, strlen of src is 8, 9, 10. In these cases, the dest alignment code does a ldr which reads 4 bytes, and it will read past the end of the source. In most cases, this is probably benign, but if this crosses into a new page it could cause a crash. Fix the labels in the cortex-a9 strcat. Modify the overread test to vary the dst alignment to expost this bug. Also, shrink the strcat/strlcat overread cases since the dst alignment variation increases the runtime too much. Bug: 24345899 Change-Id: Ib34a559bfcebd89861985b29cae6c1e47b5b5855
* Add GNU extensions mempcpy and wmemcpy.Elliott Hughes2015-02-181-0/+5
| | | | | | | Used by elfutils. On the bright side, they stopped using __mempcpy. Bug: 18374026 Change-Id: Id29bbe6ef1c5ed5a171bb6c32182f129d8332abb
* Fix memchr overflow.Elliott Hughes2015-02-141-0/+10
| | | | | | | | | The overflow's actually in the generic C implementation of memchr. While I'm here, let's switch our generic memrchr to the OpenBSD version too. Bug: https://code.google.com/p/android/issues/detail?id=147048 Change-Id: I296ae06a1ee196d2c77c95a22f11ee4d658962da
* Add align/overread tests for strlcpy/strlcat.Christopher Ferris2014-11-101-9/+93
| | | | Change-Id: I2801c7ee1847cd68ec95eba5bdffde5e52edf1e5
* Reset enviroment for math_testsDmitriy Ivanov2014-09-041-9/+9
| | | | | Bug: 17390824 Change-Id: I42f4c8d9199a2efe7641f0b0e64580cacb5695da
* Merge "Make string tests check all alignment combinations"Dmitriy Ivanov2014-09-031-101/+88
|\
| * Make string tests check all alignment combinationsDmitriy Ivanov2014-08-141-101/+88
| | | | | | | | | | | | | | | | Reduce randomization of the test by (1) replacing random() & 255 with hard-coded char and (2) by making State *Iteration function visit every possible alignment combination instead of 10 random ones. Change-Id: I0ff0b4ca817ba9fbbcce53e09b25eb10a1a853c2
* | Add GNU-compatible strerror_r.Elliott Hughes2014-08-281-11/+19
| | | | | | | | | | | | | | | | | | | | | | | | We already had the POSIX strerror_r, but some third-party code defines _GNU_SOURCE and expects to get the GNU strerror_r instead. This exposed a bug in the libc internal logging functions where unlike their standard brethren they wouldn't return the number of bytes they'd have liked to have written. Bug: 16243479 Change-Id: I1745752ccbdc569646d34f5071f6df2be066d5f4
* | Implement the GNU basename(3) in addition to the POSIX one.Elliott Hughes2014-08-191-2/+21
|/ | | | | | | Code like perf(1) needs this. Bug: 11860789 Change-Id: I907eb448052a7b165e4012d74303330d32328cb2
* Fix memchr with a zero length.Christopher Ferris2014-07-301-0/+8
| | | | | | | | | | | | | The memchr implementation for 64 bit fails if these conditions occur: - The buffer is 32 byte aligned. - The buffer contains the character in the first byte. - The count sent in is zero. The function should return NULL, but it's not. Bug: 16676625 Change-Id: Iab33cc7a8b79920350c72f054dff0e0a3cde69ce
* Add extra strchr testing.Christopher Ferris2014-06-301-0/+44
| | | | Change-Id: Idd0a779eb3388e402cfcb4e0df40872320f8e155
* Revert "Backing this one out since the counterpart needs to be sent upstream."Dan Albert2014-06-141-3/+4
| | | | | | This reverts commit a04d2bc28e7d7fcaf34ad71e4a6608a13cf84197. Change-Id: I1b49165ca5d4bafdba7948818256a6167a363aca
* Backing this one out since the counterpart needs to be sent upstream.Dan Albert2014-06-141-4/+3
| | | | | | This reverts commit 5ee320dd35fafc11eaf90c62198e08c6670e35b4. Change-Id: I1a9c6b06c3aca595f01c629f7649be743dc48e77
* Hides valloc(3)/pvalloc(3) on LP64.Dan Albert2014-06-131-3/+4
| | | | | | | | These were removed from POSIX 2004. Hides the header declarations for all targets, and hides the symbols for LP64. Bug: 13935372 Change-Id: Id592f67e9b7051517a05f536e1373b30162e669c
* Remove __memcmp16 from bionic.Elliott Hughes2014-06-121-31/+0
| | | | Change-Id: I2486d667d96c8900dd368d855f37c1327161efb7
* AArch64: Fix memcmp16() testSerban Constantinescu2014-06-101-1/+1
| | | | | | | | __memcmp16() should return an integer less than, equal to, or greater than zero. However the tests looks for a specific value. Change-Id: I06052f58f9ccc67146a3df9abb349c4bc19f090e Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
* Fix for slm-tuned memmove (both 32- and 64-bit).Varvara Rainchik2014-06-051-0/+29
| | | | | | | | Introduce a test for memmove that catches a fault. Fix both 32- and 64-bit versions of slm-tuned memmove. Change-Id: Ib416def2610a0972e32c3b9b6055b54967643dc3 Signed-off-by: Varvara Rainchik <varvara.rainchik@intel.com>
* denver: optimize memmoveShu Zhang2014-05-201-0/+66
| | | | | | Optimize 32-bit denver memmove with reversal memcpy. Change-Id: Iaad0a9475248cdd7e4f50d58bea9db1b767abc88
* Make SIGRTMIN hide the real-time signals we use internally.Elliott Hughes2014-04-301-5/+3
| | | | | | | | __SIGRTMIN will continue to tell the truth. This matches glibc's behavior (as evidenced by the fact that we don't need a special case in the strsignal test now). Change-Id: I1abe1681d516577afa8cd39c837ef12467f68dd2
* Add stpcpy/stpncpy.Christopher Ferris2014-04-071-83/+152
| | | | | | | | | | | | | | Add tests for the above. Add the fortify implementations of __stpcpy_chk and __stpncpy_chk. Modify the strncpy test to cover more cases and use this template for stpncpy. Add all of the fortify test cases. Bug: 13746695 Change-Id: I8c0f0d4991a878b8e8734fff12c8b73b07fdd344
* Make sure that the same tests are on all platforms.Christopher Ferris2014-02-061-12/+23
| | | | | | | | | | | | | | | | In order to be able to generate a list of tests for cts, the same set of tests must exist across all platforms. This CL adds empty tests where a test was conditionally compiled out. This CL creates a single library libBionicTests that includes all of the tests found in bionic-unit-tests-static. Also fix a few missing include files in some test files. Tested by running and compiling the tests for every platform and verifying the same number of tests are on each platform. Change-Id: I9989d4bfebb0f9c409a0ce7e87169299eac605a2
* Add strcmp/memcmp testing.Christopher Ferris2013-12-031-2/+87
| | | | | Bug: 9797008 Change-Id: I11b1da060d29f7dacbb53f20a3e2082395b5bd8a
* Add new tests for memory/string routines.Christopher Ferris2013-11-151-0/+122
| | | | | | | | | | | | | | | Create a few generic testing functions to allow any memory/string tests to be created. Add alignment tests for memcpy/memset/strcat/strcpy/strlen. Add an overread test for memcpy/strcat/strcpy/strlen. This test attempts to verify that the functions do not read past the end of their buffers (src buffer in the case of src/dst functions). Bug: 9797008 Change-Id: Ib3223ca1b99e729ae8229adc2d03f4dc3103d97c
* Add ssse3 implementation of __memcmp16.Alexander Ivchenko2013-08-021-23/+77
| | | | | | | | __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>
* Add tests for __strcpy_chk()Nick Kralevich2013-06-041-0/+47
| | | | Change-Id: I5675d04fcd471732c1b87b83879a54fbcd27762e
* FORTIFY_SOURCE: strcat / strncat optimizeNick Kralevich2013-05-311-0/+114
| | | | | | | | | | | | | | | | __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
* libc: cleanup strchrNick Kralevich2013-05-021-0/+7
| | | | | | Move strchr to a .cpp file, and change to bionic directory. Change-Id: I64ade7df326c0a9a714aca4caf5647b6833b1c97
* strncpy: implement _FORTIFY_SOURCE=2Nick Kralevich2013-04-291-33/+0
| | | | | | | | | | | | | | | | 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
* FORTIFY_SOURCE: optimizeNick Kralevich2013-01-171-0/+21
| | | | | | | | | | | | | | | | | | | Don't do the fortify_source checks if we can determine, at compile time, that the provided operation is safe. This avoids silliness like calling fortify source on things like: size_t len = strlen("asdf"); printf("%d\n", len); and allows the compiler to optimize this code to: printf("%d\n", 4); Defer to gcc's builtin functions instead of pointing our code to the libc implementation. Change-Id: I5e1dcb61946461c4afaaaa983e39f07c7a0df0ae
* fix strerror_r testNick Kralevich2013-01-151-1/+1
| | | | | | | | | | e6e60065ff093ff8c859ab146cf543531cb1967c modified strerror_r to treat errno as signed. However, the change to the test code modified the "strerror" test, not the "strerror_r" test. Make the same change for the strerror_r code. Change-Id: Ia236a53df5745935e229a4446a74da8bed0cfd7b
* Add stack canaries / strcpy tests.Nick Kralevich2013-01-111-0/+13
| | | | | | | | | | | Add a test to ensure that stack canaries are working correctly. Since stack canaries aren't normally generated on non-string functions, we have to enable stack-protector-all. Add a test to ensure that an out of bounds strcpy generates a runtime failure. Change-Id: Id0d3e59fc4b9602da019e4d35c5c653e1a57fae4
* glibc 2.15 treats errno as signed in strerror(3).Elliott Hughes2013-01-101-1/+1
| | | | | | | And the only reason I hadn't done that in bionic is because I wanted to behave the same as glibc. Change-Id: I2cf1bf0aac82a748cd6305a2cabbac0790058570
* Tests for string routines.Anna Tikhonova2012-11-071-0/+555
| | | | | Change-Id: I24068a228f59df1c3b758c5b2026a09720490616 Signed-off-by: Anna Tikhonova <anna.tikhonova@intel.com>
* Per-thread -fstack-protector guards for x86.Elliott Hughes2012-10-251-3/+5
| | | | | | | | | | | | | | | | | Based on a pair of patches from Intel: https://android-review.googlesource.com/#/c/43909/ https://android-review.googlesource.com/#/c/44903/ For x86, this patch supports _both_ the global that ARM/MIPS use and the per-thread TLS entry (%gs:20) that GCC uses by default. This lets us support binaries built with any x86 toolchain (right now, the NDK is emitting x86 code that uses the global). I've also extended the original tests to cover ARM/MIPS too, and be a little more thorough for x86. Change-Id: I02f279a80c6b626aecad449771dec91df235ad01
* Make dlerror(3) thread-safe.Elliott Hughes2012-10-161-2/+2
| | | | | | | | | | | | | I gave up trying to use the usual thread-local buffer idiom; calls to calloc(3) and free(3) from any of the "dl" functions -- which live in the dynamic linker -- end up resolving to the dynamic linker's stubs. I tried to work around that, but was just making things more complicated. This alternative costs us a well-known TLS slot (instead of the dynamically-allocated TLS slot we'd have used otherwise, so no difference there), plus an extra buffer inside every pthread_internal_t. Bug: 5404023 Change-Id: Ie9614edd05b6d1eeaf7bf9172792d616c6361767
* Make strerror(3) and strsignal(3) thread-safe, and add psignal(3) and ↵Irina Tirdea2012-09-131-0/+107
psiginfo(3). Change-Id: I426109db25e907980d6cb3a7a695796e45783b78