summaryrefslogtreecommitdiffstats
path: root/libc/include
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2012-12-03 10:36:13 -0800
committerNick Kralevich <nnk@google.com>2012-12-03 10:39:16 -0800
commit9a4d305340e6ce2fc6c3f371f2d7ede446f8c6d4 (patch)
treee6c29deaf1b6789aa94bb1074db1b9b554033267 /libc/include
parent60fb68338b7541b6022fc343857b90c088c399cd (diff)
downloadbionic-9a4d305340e6ce2fc6c3f371f2d7ede446f8c6d4.zip
bionic-9a4d305340e6ce2fc6c3f371f2d7ede446f8c6d4.tar.gz
bionic-9a4d305340e6ce2fc6c3f371f2d7ede446f8c6d4.tar.bz2
FORTIFY_SOURCE: fortify strrchr
This change compliments 049e58369c37fdeacd0380a6bf1e078d9baf819f Change-Id: I27d015d70a520713c7472558a3c427f546d36ee4
Diffstat (limited to 'libc/include')
-rw-r--r--libc/include/string.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/libc/include/string.h b/libc/include/string.h
index 32b9310..2ed74e8 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -240,6 +240,22 @@ char* strchr(const char *s, int c) {
return __strchr_chk(s, c, bos);
}
+__purefunc extern char* __strrchr_real(const char *, int)
+ __asm__(__USER_LABEL_PREFIX__ "strrchr");
+extern char* __strrchr_chk(const char *, int, size_t);
+
+__BIONIC_FORTIFY_INLINE
+char* strrchr(const char *s, int c) {
+ size_t bos = __builtin_object_size(s, 0);
+
+ // Compiler doesn't know destination size. Don't call __strrchr_chk
+ if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
+ return __strrchr_real(s, c);
+ }
+
+ return __strrchr_chk(s, c, bos);
+}
+
#endif /* defined(__BIONIC_FORTIFY_INLINE) */