summaryrefslogtreecommitdiffstats
path: root/libc/string
Commit message (Collapse)AuthorAgeFilesLines
* Drop magic number in strrchr and strchrKito Cheng2013-03-222-2/+2
| | | | Change-Id: Ic7391be8575eaaac76914dab62bc41c9773d703d
* Clean up internal libc logging.Elliott Hughes2013-03-152-2/+2
| | | | | | | | | | | We only need one logging API, and I prefer the one that does no allocation and is thus safe to use in any context. Also use O_CLOEXEC when opening the /dev/log files. Move everything logging-related into one header file. Change-Id: Ic1e3ea8e9b910dc29df351bff6c0aa4db26fbb58
* clean up FORTIFY_SOURCE handling.Nick Kralevich2012-12-042-10/+4
| | | | | | Avoid duplicating huge chunks of code. Change-Id: Id6145cdfce781c5ffba2abaaa79681d25a7ab28f
* FORTIFY_SOURCE: fortify strrchrNick Kralevich2012-12-031-2/+14
| | | | | | This change compliments 049e58369c37fdeacd0380a6bf1e078d9baf819f Change-Id: I27d015d70a520713c7472558a3c427f546d36ee4
* FORTIFY_SOURCE: fortify strchrNick Kralevich2012-11-301-2/+13
| | | | | | Detect when strchr reads off the end of a buffer. Change-Id: I0e952eedcff5c36d646a9c3bc4e1337b959224f2
* Upgrade more functions to the current upstream NetBSD copy.Elliott Hughes2012-10-231-60/+0
| | | | Change-Id: Ie0b3f8b3fccef28609eb210434413ebd51d6ef45
* Move non-upstream code into the libc/bionic directory.Elliott Hughes2012-10-0123-1195/+0
| | | | | | | I'll need at least one more pass, because there's some upstream code lurking in libc/bionic, but this is still a step in the right direction. Change-Id: I55927315972da8327ae01c5240ed587db17e8462
* Make strerror(3) and strsignal(3) thread-safe, and add psignal(3) and ↵Irina Tirdea2012-09-132-204/+0
| | | | | | psiginfo(3). Change-Id: I426109db25e907980d6cb3a7a695796e45783b78
* Revert "Revert "Switch to NetBSD's strxfrm(3).""Elliott Hughes2012-08-101-47/+0
| | | | | | | | This reverts commit 8793e7c7d21a0434d1b5e63364c88b2b125a3d29, and fixes the build by building upstream NetBSD source as a separate library that's then swallowed whole into libc_common. Change-Id: I6c9317d8c48b5ccaf85a7b185bc07fb31176ff97
* Revert "Switch to NetBSD's strxfrm(3)."Elliott Hughes2012-08-101-0/+47
| | | | | | This reverts commit be1d78b0dc899a732c0e9d7515d3023e8004e368 Change-Id: I11a95db474796f3da004f27652b081d5ba4ec9b4
* Switch to NetBSD's strxfrm(3).Elliott Hughes2012-08-101-47/+0
| | | | | | | | There were two bugs in our implementation. Intel found one, but another remainined, and tracking upstream is the way forward for functions where we add no value. Change-Id: Ida9bac0293fb2c4cbc942b1e0515ee0477c6538b
* Error numbers are target specific.Chris Dearman2012-08-011-1/+1
| | | | | | | | Use the system supplied error numbers when mapping error numbers to messages. Change-Id: I520556fa3e2ff668fdc4eda36ad31491fbb48ea8 Signed-off-by: Chris Dearman <chris@mips.com> Signed-off-by: Raghu Gandham <raghu@mips.com>
* FORTIFY_SOURCE: revert memcpy changes.Nick Kralevich2012-07-131-29/+3
| | | | | | | | Performance regressions. Hopefully this is a temporary rollback. Bug: 6821003 Change-Id: I84abbb89e1739d506b583f2f1668f31534127764
* FORTIFY_SOURCE: strlen check.Nick Kralevich2012-07-131-0/+67
| | | | | | | | | | | | | | | | | | This test is designed to detect code such as: int main() { char buf[10]; memcpy(buf, "1234567890", sizeof(buf)); size_t len = strlen(buf); // segfault here with _FORTIFY_SOURCE printf("%d\n", len); return 0; } or anytime strlen reads beyond an object boundary. This should help address memory leakage vulnerabilities and make other unrelated vulnerabilities harder to exploit. Change-Id: I354b425be7bef4713c85f6bab0e9738445e00182
* FORTIFY_SOURCE: restore __memcpy_chk()Nick Kralevich2012-07-131-0/+10
| | | | | | | | | | | | | | | | In our previous FORTIFY_SOURCE change, we started using a custom inline for memcpy(), rather than using GCC's __builtin_memcpy_chk(). This allowed us to delete our copy of __memcpy_chk(), and replace it by __memcpy_chk2(). Apparently GCC uses __memcpy_chk() outside of __builtin_memcpy_chk(). Specifically, __memcpy_chk() is used by __builtin__memMOVE_chk() under certain optimization levels. Keep the old __memcpy_chk() function around, and have it call into __memcpy_chk2(). Change-Id: I2453930b24b8a492a3b6ed860e18d92a6b762b80
* FORTIFY_SOURCE: enhanced memcpy protections.Nick Kralevich2012-07-122-5/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Two changes: 1) Detect memory read overruns. For example: int main() { char buf[10]; memcpy(buf, "abcde", sizeof(buf)); sprintf("%s\n", buf); } because "abcde" is only 6 bytes, copying 10 bytes from it is a bug. This particular bug will be detected at compile time. Other similar bugs may be detected at runtime. 2) Detect overlapping buffers on memcpy() It is a bug to call memcpy() on buffers which overlap. For example, the following code is buggy: char buf3[0x800]; char *first_half = &buf3[0x400]; char *second_half = &buf3[1]; memset(buf3, 0, sizeof(buf3)); memcpy(first_half, second_half, 0x400); printf("1: %s\n", buf3); We now detect this at compile and run time. Change-Id: I092bd89f11f18e08e8a9dda0ca903aaea8e06d91
* memmove: Don't call memcpy if regions overlapNick Kralevich2012-07-111-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | memmove() unconditionally calls memcpy() if "dst" < "src". For example, in the code below, memmove() would end up calling memcpy(), even though the regions of memory overlap. int main() { char buf3[0x800]; char *dst = &buf3[1]; char *src = &buf3[0x400]; memset(buf3, 0, sizeof(buf3)); memmove(dst, src, 0x400); printf("1: %s\n", buf3); return 0; } Calling memcpy() on overlaping regions only works if you assume that memcpy() copies from start to finish. On some architectures, it's more efficient to call memcpy() from finish to start. This is also triggering a failure in some of my code. More reading: * http://lwn.net/Articles/414467/ * https://bugzilla.redhat.com/show_bug.cgi?id=638477#c31 (comment 31) Change-Id: I65a51ae3a52dd4af335fe5c278056b8c2cbd8948
* FORTIFY_SOURCE: add strlcpy / strlcat supportNick Kralevich2012-06-142-0/+110
| | | | | | | | | | | | | Add strlcpy / strlcat support to FORTIFY_SOURCE. This allows us to do consistency checks on to ensure we don't overflow buffers when the compiler is able to tell us the size of the buffer we're dealing with. Unlike previous changes, this change DOES NOT use the compiler's builtin support. Instead, we do everything the compiler would normally do. Change-Id: I47c099a911382452eafd711f8e9bfe7c2d0a0d22
* Added actual event logging calls to the FORTIFY_SOURCE methods.Geremy Condra2012-06-117-2/+19
| | | | Change-Id: I3bf4fa8678c33187cb8ce4b75e666ddcd24403ab
* _FORTIFY_SOURCE: check for integer overflowsNick Kralevich2012-06-082-2/+12
| | | | | | | Ensure that strcat / strncat check for integer overflows when computing the length of the resulting string. Change-Id: Ib806ad33a0d3b50876f384bc17787a28f0dddc37
* _FORTIFY_SOURCE: add memset / bzero supportNick Kralevich2012-06-071-0/+53
| | | | | | | | | | | | Add _FORTIFY_SOURCE support for the following functions: * memset * bzero Move the __BIONIC_FORTIFY_INLINE definition to cdefs.h so it can be used from multiple header files. Change-Id: Iead4d5e35de6ec97786d58ee12573f9b11135bb7
* libc: implement some FORTIFY_SOURCE functionsNick Kralevich2012-06-056-0/+335
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add initial support for -D_FORTIFY_SOURCE to bionic for the following functions: * memcpy * memmove * strcpy * strcat * strncpy * strncat This change adds a new version of the above functions which passes the size of the destination buffer to __builtin___*_chk. If the compiler can determine, at compile time, that the destination buffer is large enough, or the destination buffer can point to an object of unknown size, then the check call is bypassed. If the compiler can't make a compile time decision, then it calls the __*_chk() function, which does a runtime buffer size check These options are only enabled if the code is compiled with -D_FORTIFY_SOURCE=1 or 2, and only when optimizations are enabled. Please see * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html for additional details on FORTIFY_SOURCE. Testing: Compiled the entire Android tree with -D_FORTIFY_SOURCE=1, and verified that everything appears to be working properly. Also created a test buffer overflow, and verified that it was caught by this change. Change-Id: I4fddb445bafe92b16845b22458d72e6dedd24fbc
* string: Fix wrong comparison semanticsBruce Beare2011-12-054-7/+7
| | | | | | | | Chars are signed for x86 -- correct the comparison semantics. Change-Id: I2049e98eb063c0b4e83ea973d3fcae49c6817dde Author: Liubov Dmitrieva <liubov.dmitrieva@intel.com> Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
* Fix strerror(3) for errno 0.Elliott Hughes2011-05-131-1/+1
| | | | | | | Everyone else's C library says "Success". We say "Unknown error: 0", which isn't really true. Change-Id: I9f9054779123eda996634e5f7a277789b6805809
* Use more optimized version of memmoveJohannes Carlsson2011-02-031-34/+3
| | | | | | | | | On ARM there is currently no assembler optimized memmove in libc. There is however a more optimized bcopy which copies long instead of bytes where possible. This almost doubles the performance in best case. Change-Id: I1f1cd27529443358047c385730deaf938ce4e642
* libc: optimize memmove() with memcpy() if possible.David 'Digit' Turner2010-10-071-1/+4
| | | | Change-Id: I90e578fdc82e427caee8fa4157ce3f8c6c99926d
* Revert "libc: memmove(): non-overlapping block optim."Marco Nelissen2010-09-281-5/+1
| | | | | | | | This reverts commit 80fba9a2fe4eacaabee99cf0bbead872c2792231, which caused the system to not boot anymore, aborting with: "java.lang.RuntimeException: Missing static main on com.android.server.SystemServer". Change-Id: I745e0a23c728cccf5f95a3c7642d544478a4e57e
* libc: memmove(): non-overlapping block optim.David 'Digit' Turner2010-09-271-1/+5
| | | | Change-Id: I5652f4f97ca59d95176443fc27c737ef76258183
* Fix return value.rich cannings2010-08-311-10/+1
| | | | | | | | Return a valid pointer (not NULL) when the character "c" is at the end of "src". Change-Id: Iab0b677943f2c8a9fbb255c44689f5d6dc3535d7 Example: memccpy(dest, "xzy", 'y', 3) should return dest+3 rather than null.
* Merge "string: tidy up strndup()"David Turner2010-05-101-4/+6
|\
| * string: tidy up strndup()André Goddard Rosa2010-01-301-4/+6
| | | | | | | | | | | | | | | | | | It decreases code size: text data bss dec hex filename 161 0 0 161 a1 strndup-BEFORE.o 153 0 0 153 99 strndup-AFTER.o Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
* | Merge changes Ibdc6e3c8,I9bcb91a2David Turner2010-03-292-5/+5
|\ \ | |/ |/| | | | | | | * changes: Correct generic memset implementation Generic memcpy should define MEMCOPY before including bcopy.c
| * Correct generic memset implementationChris Dearman2010-02-051-4/+4
| | | | | | | | Signed-off-by: Chris Dearman <chris@mips.com>
| * Generic memcpy should define MEMCOPY before including bcopy.cChris Dearman2010-02-051-1/+1
| | | | | | | | Signed-off-by: Chris Dearman <chris@mips.com>
* | improve readability of string: fix indentation and remove trailing spacesAndré Goddard Rosa2010-01-3013-18/+17
|/ | | | Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
* auto import from //depot/cupcake/@135843The Android Open Source Project2009-03-0338-0/+2195
|
* auto import from //depot/cupcake/@135843The Android Open Source Project2009-03-0338-2195/+0
|
* auto import from //branches/cupcake/...@130745The Android Open Source Project2009-02-102-0/+87
|
* Initial Contributionandroid-1.0The Android Open Source Project2008-10-2136-0/+2108