George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #ifndef _STRING_H |
| 30 | #error "Never include this file directly; instead, include <string.h>" |
| 31 | #endif |
| 32 | |
Elliott Hughes | 3f66e74 | 2017-08-01 13:24:40 -0700 | [diff] [blame] | 33 | void* __memchr_chk(const void*, int, size_t, size_t) __INTRODUCED_IN(23); |
| 34 | void* __memrchr_chk(const void*, int, size_t, size_t) __INTRODUCED_IN(23); |
| 35 | char* __stpncpy_chk2(char*, const char*, size_t, size_t, size_t) __INTRODUCED_IN(21); |
| 36 | char* __strncpy_chk2(char*, const char*, size_t, size_t, size_t) __INTRODUCED_IN(21); |
| 37 | size_t __strlcpy_chk(char*, const char*, size_t, size_t) __INTRODUCED_IN(17); |
| 38 | size_t __strlcat_chk(char*, const char*, size_t, size_t) __INTRODUCED_IN(17); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 39 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 40 | #if defined(__BIONIC_FORTIFY) |
Elliott Hughes | df9a489 | 2017-08-23 14:34:03 -0700 | [diff] [blame] | 41 | extern void* __memrchr_real(const void*, int, size_t) __RENAME(memrchr); |
| 42 | |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 43 | #if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 44 | /* No diag -- clang diagnoses misuses of this on its own. */ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 45 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 46 | void* memcpy(void* const dst __pass_object_size0, const void* src, size_t copy_amount) |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 47 | __overloadable { |
George Burgess IV | 2f78765 | 2020-02-04 21:40:40 -0800 | [diff] [blame] | 48 | return __builtin___memcpy_chk(dst, src, copy_amount, __bos0(dst)); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 49 | } |
| 50 | |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 51 | /* No diag -- clang diagnoses misuses of this on its own. */ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 52 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 53 | void* memmove(void* const dst __pass_object_size0, const void* src, size_t len) __overloadable { |
George Burgess IV | 2f78765 | 2020-02-04 21:40:40 -0800 | [diff] [blame] | 54 | return __builtin___memmove_chk(dst, src, len, __bos0(dst)); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 55 | } |
George Burgess IV | 8a0cdb1 | 2019-10-21 13:27:57 -0700 | [diff] [blame] | 56 | #endif |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 57 | |
George Burgess IV | 849c0b9 | 2019-06-10 16:22:09 -0700 | [diff] [blame] | 58 | #if defined(__USE_GNU) |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 59 | #if __ANDROID_API__ >= 30 |
George Burgess IV | 849c0b9 | 2019-06-10 16:22:09 -0700 | [diff] [blame] | 60 | __BIONIC_FORTIFY_INLINE |
| 61 | void* mempcpy(void* const dst __pass_object_size0, const void* src, size_t copy_amount) |
| 62 | __overloadable |
| 63 | __clang_error_if(__bos_unevaluated_lt(__bos0(dst), copy_amount), |
| 64 | "'mempcpy' called with size bigger than buffer") { |
George Burgess IV | 8a0cdb1 | 2019-10-21 13:27:57 -0700 | [diff] [blame] | 65 | #if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
George Burgess IV | 849c0b9 | 2019-06-10 16:22:09 -0700 | [diff] [blame] | 66 | size_t bos_dst = __bos0(dst); |
George Burgess IV | 8a0cdb1 | 2019-10-21 13:27:57 -0700 | [diff] [blame] | 67 | if (!__bos_trivially_ge(bos_dst, copy_amount)) { |
| 68 | return __builtin___mempcpy_chk(dst, src, copy_amount, bos_dst); |
George Burgess IV | 849c0b9 | 2019-06-10 16:22:09 -0700 | [diff] [blame] | 69 | } |
George Burgess IV | 8a0cdb1 | 2019-10-21 13:27:57 -0700 | [diff] [blame] | 70 | #endif |
| 71 | return __builtin_mempcpy(dst, src, copy_amount); |
George Burgess IV | 849c0b9 | 2019-06-10 16:22:09 -0700 | [diff] [blame] | 72 | } |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 73 | #endif /* __ANDROID_API__ >= 30 */ |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame] | 74 | #endif /* __USE_GNU */ |
George Burgess IV | 849c0b9 | 2019-06-10 16:22:09 -0700 | [diff] [blame] | 75 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 76 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 77 | char* stpcpy(char* const dst __pass_object_size, const char* src) |
| 78 | __overloadable |
George Burgess IV | c03d596 | 2019-05-23 15:22:01 -0700 | [diff] [blame] | 79 | __clang_error_if(__bos_unevaluated_le(__bos(dst), __builtin_strlen(src)), |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 80 | "'stpcpy' called with string bigger than buffer") { |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 81 | #if __ANDROID_API__ >= 21 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
George Burgess IV | 2f78765 | 2020-02-04 21:40:40 -0800 | [diff] [blame] | 82 | return __builtin___stpcpy_chk(dst, src, __bos(dst)); |
| 83 | #else |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame] | 84 | return __builtin_stpcpy(dst, src); |
George Burgess IV | 2f78765 | 2020-02-04 21:40:40 -0800 | [diff] [blame] | 85 | #endif |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame] | 86 | } |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 87 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 88 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 89 | char* strcpy(char* const dst __pass_object_size, const char* src) |
| 90 | __overloadable |
George Burgess IV | c03d596 | 2019-05-23 15:22:01 -0700 | [diff] [blame] | 91 | __clang_error_if(__bos_unevaluated_le(__bos(dst), __builtin_strlen(src)), |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 92 | "'strcpy' called with string bigger than buffer") { |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 93 | #if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
George Burgess IV | 2f78765 | 2020-02-04 21:40:40 -0800 | [diff] [blame] | 94 | return __builtin___strcpy_chk(dst, src, __bos(dst)); |
| 95 | #else |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame] | 96 | return __builtin_strcpy(dst, src); |
George Burgess IV | 2f78765 | 2020-02-04 21:40:40 -0800 | [diff] [blame] | 97 | #endif |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 77f99aa | 2019-06-06 14:14:52 -0700 | [diff] [blame] | 101 | char* strcat(char* const dst __pass_object_size, const char* src) |
| 102 | __overloadable |
| 103 | __clang_error_if(__bos_unevaluated_le(__bos(dst), __builtin_strlen(src)), |
| 104 | "'strcat' called with string bigger than buffer") { |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 105 | #if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 106 | return __builtin___strcat_chk(dst, src, __bos(dst)); |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame] | 107 | #else |
| 108 | return __builtin_strcat(dst, src); |
George Burgess IV | 8a0cdb1 | 2019-10-21 13:27:57 -0700 | [diff] [blame] | 109 | #endif |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 112 | #if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 113 | /* No diag -- clang diagnoses misuses of this on its own. */ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 114 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 115 | char* strncat(char* const dst __pass_object_size, const char* src, size_t n) __overloadable { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 116 | return __builtin___strncat_chk(dst, src, n, __bos(dst)); |
| 117 | } |
George Burgess IV | 8a0cdb1 | 2019-10-21 13:27:57 -0700 | [diff] [blame] | 118 | #endif |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 119 | |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 120 | /* No diag -- clang diagnoses misuses of this on its own. */ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 121 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 122 | void* memset(void* const s __pass_object_size0, int c, size_t n) __overloadable |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 123 | /* If you're a user who wants this warning to go away: use `(&memset)(foo, bar, baz)`. */ |
| 124 | __clang_warning_if(c && !n, "'memset' will set 0 bytes; maybe the arguments got flipped?") { |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 125 | #if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
George Burgess IV | 2f78765 | 2020-02-04 21:40:40 -0800 | [diff] [blame] | 126 | return __builtin___memset_chk(s, c, n, __bos0(s)); |
| 127 | #else |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame] | 128 | return __builtin_memset(s, c, n); |
George Burgess IV | 2f78765 | 2020-02-04 21:40:40 -0800 | [diff] [blame] | 129 | #endif |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame] | 130 | } |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 131 | |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 132 | #if __ANDROID_API__ >= 23 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 133 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 134 | void* memchr(const void* const s __pass_object_size, int c, size_t n) __overloadable { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 135 | size_t bos = __bos(s); |
| 136 | |
George Burgess IV | c03d596 | 2019-05-23 15:22:01 -0700 | [diff] [blame] | 137 | if (__bos_trivially_ge(bos, n)) { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 138 | return __builtin_memchr(s, c, n); |
| 139 | } |
| 140 | |
| 141 | return __memchr_chk(s, c, n, bos); |
| 142 | } |
| 143 | |
| 144 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | df9a489 | 2017-08-23 14:34:03 -0700 | [diff] [blame] | 145 | void* __memrchr_fortify(const void* const __pass_object_size s, int c, size_t n) __overloadable { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 146 | size_t bos = __bos(s); |
| 147 | |
George Burgess IV | c03d596 | 2019-05-23 15:22:01 -0700 | [diff] [blame] | 148 | if (__bos_trivially_ge(bos, n)) { |
Elliott Hughes | df9a489 | 2017-08-23 14:34:03 -0700 | [diff] [blame] | 149 | return __memrchr_real(s, c, n); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | return __memrchr_chk(s, c, n, bos); |
| 153 | } |
George Burgess IV | 8a0cdb1 | 2019-10-21 13:27:57 -0700 | [diff] [blame] | 154 | #endif |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 155 | |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 156 | #if __ANDROID_API__ >= 21 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 157 | /* No diag -- clang diagnoses misuses of this on its own. */ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 158 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 3f66e74 | 2017-08-01 13:24:40 -0700 | [diff] [blame] | 159 | char* stpncpy(char* const dst __pass_object_size, const char* const src __pass_object_size, size_t n) |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 160 | __overloadable { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 161 | size_t bos_dst = __bos(dst); |
| 162 | size_t bos_src = __bos(src); |
| 163 | |
| 164 | /* Ignore dst size checks; they're handled in strncpy_chk */ |
| 165 | if (bos_src == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 166 | return __builtin___stpncpy_chk(dst, src, n, bos_dst); |
| 167 | } |
| 168 | |
| 169 | return __stpncpy_chk2(dst, src, n, bos_dst, bos_src); |
| 170 | } |
| 171 | |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 172 | /* No diag -- clang diagnoses misuses of this on its own. */ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 173 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 3f66e74 | 2017-08-01 13:24:40 -0700 | [diff] [blame] | 174 | char* strncpy(char* const dst __pass_object_size, const char* const src __pass_object_size, size_t n) |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 175 | __overloadable { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 176 | size_t bos_dst = __bos(dst); |
| 177 | size_t bos_src = __bos(src); |
| 178 | |
| 179 | /* Ignore dst size checks; they're handled in strncpy_chk */ |
| 180 | if (bos_src == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 181 | return __builtin___strncpy_chk(dst, src, n, bos_dst); |
| 182 | } |
| 183 | |
| 184 | return __strncpy_chk2(dst, src, n, bos_dst, bos_src); |
| 185 | } |
George Burgess IV | 8a0cdb1 | 2019-10-21 13:27:57 -0700 | [diff] [blame] | 186 | #endif |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 187 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 188 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 77f99aa | 2019-06-06 14:14:52 -0700 | [diff] [blame] | 189 | size_t strlcpy(char* const dst __pass_object_size, const char* src, size_t size) |
| 190 | __overloadable |
| 191 | __clang_error_if(__bos_unevaluated_lt(__bos(dst), size), |
| 192 | "'strlcpy' called with size bigger than buffer") { |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 193 | #if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
George Burgess IV | 2f78765 | 2020-02-04 21:40:40 -0800 | [diff] [blame] | 194 | return __strlcpy_chk(dst, src, size, __bos(dst)); |
| 195 | #else |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame] | 196 | return __call_bypassing_fortify(strlcpy)(dst, src, size); |
George Burgess IV | 2f78765 | 2020-02-04 21:40:40 -0800 | [diff] [blame] | 197 | #endif |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 77f99aa | 2019-06-06 14:14:52 -0700 | [diff] [blame] | 201 | size_t strlcat(char* const dst __pass_object_size, const char* src, size_t size) |
| 202 | __overloadable |
| 203 | __clang_error_if(__bos_unevaluated_lt(__bos(dst), size), |
| 204 | "'strlcat' called with size bigger than buffer") { |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 205 | #if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
George Burgess IV | 2f78765 | 2020-02-04 21:40:40 -0800 | [diff] [blame] | 206 | return __strlcat_chk(dst, src, size, __bos(dst)); |
George Burgess IV | d02e7b1 | 2020-02-13 11:44:20 -0800 | [diff] [blame^] | 207 | #else |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame] | 208 | return __call_bypassing_fortify(strlcat)(dst, src, size); |
George Burgess IV | d02e7b1 | 2020-02-13 11:44:20 -0800 | [diff] [blame^] | 209 | #endif |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 210 | } |
| 211 | |
George Burgess IV | d02e7b1 | 2020-02-13 11:44:20 -0800 | [diff] [blame^] | 212 | #if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 213 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 214 | size_t strlen(const char* const s __pass_object_size0) __overloadable { |
George Burgess IV | d02e7b1 | 2020-02-13 11:44:20 -0800 | [diff] [blame^] | 215 | return __strlen_chk(s, __bos0(s)); |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame] | 216 | } |
George Burgess IV | d02e7b1 | 2020-02-13 11:44:20 -0800 | [diff] [blame^] | 217 | #endif |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 218 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 219 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 3f66e74 | 2017-08-01 13:24:40 -0700 | [diff] [blame] | 220 | char* strchr(const char* const s __pass_object_size, int c) __overloadable { |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 221 | #if __ANDROID_API__ >= 18 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 222 | size_t bos = __bos(s); |
| 223 | |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame] | 224 | if (bos != __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 225 | return __strchr_chk(s, c, bos); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 226 | } |
George Burgess IV | 8a0cdb1 | 2019-10-21 13:27:57 -0700 | [diff] [blame] | 227 | #endif |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame] | 228 | return __builtin_strchr(s, c); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 3f66e74 | 2017-08-01 13:24:40 -0700 | [diff] [blame] | 232 | char* strrchr(const char* const s __pass_object_size, int c) __overloadable { |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 233 | #if __ANDROID_API__ >= 18 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 234 | size_t bos = __bos(s); |
| 235 | |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame] | 236 | if (bos != __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 237 | return __strrchr_chk(s, c, bos); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 238 | } |
George Burgess IV | 8a0cdb1 | 2019-10-21 13:27:57 -0700 | [diff] [blame] | 239 | #endif |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame] | 240 | return __builtin_strrchr(s, c); |
| 241 | } |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 242 | |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 243 | #if __ANDROID_API__ >= 23 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED |
Elliott Hughes | df9a489 | 2017-08-23 14:34:03 -0700 | [diff] [blame] | 244 | #if defined(__cplusplus) |
| 245 | extern "C++" { |
| 246 | __BIONIC_FORTIFY_INLINE |
| 247 | void* memrchr(void* const __pass_object_size s, int c, size_t n) { |
| 248 | return __memrchr_fortify(s, c, n); |
| 249 | } |
| 250 | |
| 251 | __BIONIC_FORTIFY_INLINE |
| 252 | const void* memrchr(const void* const __pass_object_size s, int c, size_t n) { |
| 253 | return __memrchr_fortify(s, c, n); |
| 254 | } |
| 255 | } |
| 256 | #else |
| 257 | __BIONIC_FORTIFY_INLINE |
| 258 | void* memrchr(const void* const __pass_object_size s, int c, size_t n) __overloadable { |
| 259 | return __memrchr_fortify(s, c, n); |
| 260 | } |
| 261 | #endif |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 262 | #endif /* __ANDROID_API__ >= 23 */ |
Elliott Hughes | df9a489 | 2017-08-23 14:34:03 -0700 | [diff] [blame] | 263 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 264 | #endif /* defined(__BIONIC_FORTIFY) */ |