summaryrefslogtreecommitdiffstats
path: root/libc/string/strrchr.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/string/strrchr.c')
-rw-r--r--libc/string/strrchr.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/libc/string/strrchr.c b/libc/string/strrchr.c
index 10c07e6..fc3dc4e 100644
--- a/libc/string/strrchr.c
+++ b/libc/string/strrchr.c
@@ -29,13 +29,19 @@
*/
#include <string.h>
+#include <private/logd.h>
char *
-strrchr(const char *p, int ch)
+__strrchr_chk(const char *p, int ch, size_t s_len)
{
char *save;
- for (save = NULL;; ++p) {
+ for (save = NULL;; ++p, s_len--) {
+ if (s_len == 0) {
+ __libc_android_log_print(ANDROID_LOG_FATAL, "libc",
+ "*** FORTIFY_SOURCE strrchr read beyond buffer ***\n");
+ abort();
+ }
if (*p == (char) ch)
save = (char *)p;
if (!*p)
@@ -43,3 +49,9 @@ strrchr(const char *p, int ch)
}
/* NOTREACHED */
}
+
+char *
+strrchr(const char *p, int ch)
+{
+ return __strrchr_chk(p, ch, (size_t) -1);
+}