diff options
Diffstat (limited to 'libc/string/strchr.c')
-rw-r--r-- | libc/string/strchr.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/libc/string/strchr.c b/libc/string/strchr.c index 9b4332c..44516ef 100644 --- a/libc/string/strchr.c +++ b/libc/string/strchr.c @@ -29,11 +29,17 @@ */ #include <string.h> +#include <private/logd.h> char * -strchr(const char *p, int ch) +__strchr_chk(const char *p, int ch, size_t s_len) { - for (;; ++p) { + for (;; ++p, s_len--) { + if (s_len == 0) { + __libc_android_log_print(ANDROID_LOG_FATAL, "libc", + "*** FORTIFY_SOURCE strchr read beyond buffer ***\n"); + abort(); + } if (*p == (char) ch) return((char *)p); if (!*p) @@ -41,3 +47,8 @@ strchr(const char *p, int ch) } /* NOTREACHED */ } + +char * +strchr(const char *p, int ch) { + return __strchr_chk(p, ch, (size_t) -1); +} |