summaryrefslogtreecommitdiffstats
path: root/libc/include/string.h
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2012-11-30 15:15:58 -0800
committerNick Kralevich <nnk@google.com>2012-11-30 15:19:15 -0800
commit049e58369c37fdeacd0380a6bf1e078d9baf819f (patch)
tree039599b75477a0759c69af2295e3dd20f293caff /libc/include/string.h
parent16c61f088524756ef0fa1b030719f6745eaef2db (diff)
downloadbionic-049e58369c37fdeacd0380a6bf1e078d9baf819f.zip
bionic-049e58369c37fdeacd0380a6bf1e078d9baf819f.tar.gz
bionic-049e58369c37fdeacd0380a6bf1e078d9baf819f.tar.bz2
FORTIFY_SOURCE: fortify strchr
Detect when strchr reads off the end of a buffer. Change-Id: I0e952eedcff5c36d646a9c3bc4e1337b959224f2
Diffstat (limited to 'libc/include/string.h')
-rw-r--r--libc/include/string.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/libc/include/string.h b/libc/include/string.h
index 06e2284..32b9310 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -224,6 +224,23 @@ size_t strlen(const char *s) {
return __strlen_chk(s, bos);
}
+__purefunc extern char* __strchr_real(const char *, int)
+ __asm__(__USER_LABEL_PREFIX__ "strchr");
+extern char* __strchr_chk(const char *, int, size_t);
+
+__BIONIC_FORTIFY_INLINE
+char* strchr(const char *s, int c) {
+ size_t bos = __builtin_object_size(s, 0);
+
+ // Compiler doesn't know destination size. Don't call __strchr_chk
+ if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
+ return __strchr_real(s, c);
+ }
+
+ return __strchr_chk(s, c, bos);
+}
+
+
#endif /* defined(__BIONIC_FORTIFY_INLINE) */
__END_DECLS