summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libc/bionic/__FD_chk.cpp18
-rw-r--r--libc/bionic/__fgets_chk.cpp19
-rw-r--r--libc/bionic/__memcpy_chk.cpp15
-rw-r--r--libc/bionic/__memmove_chk.cpp15
-rw-r--r--libc/bionic/__memset_chk.cpp12
-rw-r--r--libc/bionic/__read_chk.cpp4
-rw-r--r--libc/bionic/__recvfrom_chk.cpp5
-rw-r--r--libc/bionic/__strcat_chk.cpp29
-rw-r--r--libc/bionic/__strchr_chk.cpp2
-rw-r--r--libc/bionic/__strcpy_chk.cpp16
-rw-r--r--libc/bionic/__strlcat_chk.cpp13
-rw-r--r--libc/bionic/__strlcpy_chk.cpp13
-rw-r--r--libc/bionic/__strlen_chk.cpp12
-rw-r--r--libc/bionic/__strncat_chk.cpp43
-rw-r--r--libc/bionic/__strncpy_chk.cpp9
-rw-r--r--libc/bionic/__strrchr_chk.cpp24
-rw-r--r--libc/bionic/__umask_chk.cpp8
-rw-r--r--libc/bionic/__vsnprintf_chk.cpp41
-rw-r--r--libc/bionic/__vsprintf_chk.cpp43
-rw-r--r--libc/bionic/libc_logging.cpp2
-rw-r--r--libc/bionic/open.c35
-rw-r--r--libc/bionic/openat.c36
22 files changed, 182 insertions, 232 deletions
diff --git a/libc/bionic/__FD_chk.cpp b/libc/bionic/__FD_chk.cpp
index 5c2338d..af8427a 100644
--- a/libc/bionic/__FD_chk.cpp
+++ b/libc/bionic/__FD_chk.cpp
@@ -32,39 +32,39 @@
extern "C" int __FD_ISSET_chk(int fd, fd_set* set, size_t set_size) {
if (__predict_false(fd < 0)) {
- __fortify_chk_fail("file descriptor is negative for FD_ISSET", 0);
+ __fortify_chk_fail("FD_ISSET: file descriptor < 0", 0);
}
if (__predict_false(fd >= FD_SETSIZE)) {
- __fortify_chk_fail("file descriptor is too big for FD_ISSET", 0);
+ __fortify_chk_fail("FD_ISSET: file descriptor >= FD_SETSIZE", 0);
}
if (__predict_false(set_size < sizeof(fd_set))) {
- __fortify_chk_fail("set is too small", 0);
+ __fortify_chk_fail("FD_ISSET: set is too small", 0);
}
return FD_ISSET(fd, set);
}
extern "C" void __FD_CLR_chk(int fd, fd_set* set, size_t set_size) {
if (__predict_false(fd < 0)) {
- __fortify_chk_fail("file descriptor is negative for FD_CLR", 0);
+ __fortify_chk_fail("FD_CLR: file descriptor < 0", 0);
}
if (__predict_false(fd >= FD_SETSIZE)) {
- __fortify_chk_fail("file descriptor is too big for FD_CLR", 0);
+ __fortify_chk_fail("FD_CLR: file descriptor >= FD_SETSIZE", 0);
}
if (__predict_false(set_size < sizeof(fd_set))) {
- __fortify_chk_fail("set is too small", 0);
+ __fortify_chk_fail("FD_CLR: set is too small", 0);
}
FD_CLR(fd, set);
}
extern "C" void __FD_SET_chk(int fd, fd_set* set, size_t set_size) {
if (__predict_false(fd < 0)) {
- __fortify_chk_fail("file descriptor is negative for FD_SET", 0);
+ __fortify_chk_fail("FD_SET: file descriptor < 0", 0);
}
if (__predict_false(fd >= FD_SETSIZE)) {
- __fortify_chk_fail("file descriptor is too big for FD_SET", 0);
+ __fortify_chk_fail("FD_SET: file descriptor >= FD_SETSIZE", 0);
}
if (__predict_false(set_size < sizeof(fd_set))) {
- __fortify_chk_fail("set is too small", 0);
+ __fortify_chk_fail("FD_SET: set is too small", 0);
}
FD_SET(fd, set);
}
diff --git a/libc/bionic/__fgets_chk.cpp b/libc/bionic/__fgets_chk.cpp
index fc903e4..61dad70 100644
--- a/libc/bionic/__fgets_chk.cpp
+++ b/libc/bionic/__fgets_chk.cpp
@@ -41,16 +41,15 @@
* This fgets check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-extern "C" char *__fgets_chk(char *dest, int supplied_size,
- FILE *stream, size_t dest_len_from_compiler)
-{
- if (supplied_size < 0) {
- __fortify_chk_fail("fgets buffer size less than 0", 0);
- }
+extern "C" char* __fgets_chk(char* dest, int supplied_size,
+ FILE* stream, size_t dest_len_from_compiler) {
+ if (supplied_size < 0) {
+ __fortify_chk_fail("fgets: buffer size < 0", 0);
+ }
- if (((size_t) supplied_size) > dest_len_from_compiler) {
- __fortify_chk_fail("fgets prevented write past end of buffer", 0);
- }
+ if (((size_t) supplied_size) > dest_len_from_compiler) {
+ __fortify_chk_fail("fgets: prevented write past end of buffer", 0);
+ }
- return fgets(dest, supplied_size, stream);
+ return fgets(dest, supplied_size, stream);
}
diff --git a/libc/bionic/__memcpy_chk.cpp b/libc/bionic/__memcpy_chk.cpp
index 9416e49..8a4f207 100644
--- a/libc/bionic/__memcpy_chk.cpp
+++ b/libc/bionic/__memcpy_chk.cpp
@@ -42,13 +42,12 @@
* This memcpy check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-extern "C" void *__memcpy_chk(void *dest, const void *src,
- size_t copy_amount, size_t dest_len)
-{
- if (__predict_false(copy_amount > dest_len)) {
- __fortify_chk_fail("memcpy prevented write past end of buffer",
- BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW);
- }
+extern "C" void* __memcpy_chk(void* dest, const void* src,
+ size_t copy_amount, size_t dest_len) {
+ if (__predict_false(copy_amount > dest_len)) {
+ __fortify_chk_fail("memcpy: prevented write past end of buffer",
+ BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW);
+ }
- return memcpy(dest, src, copy_amount);
+ return memcpy(dest, src, copy_amount);
}
diff --git a/libc/bionic/__memmove_chk.cpp b/libc/bionic/__memmove_chk.cpp
index b52f7c8..26bd646 100644
--- a/libc/bionic/__memmove_chk.cpp
+++ b/libc/bionic/__memmove_chk.cpp
@@ -41,13 +41,12 @@
* This memmove check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-extern "C" void *__memmove_chk (void *dest, const void *src,
- size_t len, size_t dest_len)
-{
- if (__predict_false(len > dest_len)) {
- __fortify_chk_fail("memmove prevented write past end of buffer",
- BIONIC_EVENT_MEMMOVE_BUFFER_OVERFLOW);
- }
+extern "C" void* __memmove_chk (void* dest, const void* src,
+ size_t len, size_t dest_len) {
+ if (__predict_false(len > dest_len)) {
+ __fortify_chk_fail("memmove: prevented write past end of buffer",
+ BIONIC_EVENT_MEMMOVE_BUFFER_OVERFLOW);
+ }
- return memmove(dest, src, len);
+ return memmove(dest, src, len);
}
diff --git a/libc/bionic/__memset_chk.cpp b/libc/bionic/__memset_chk.cpp
index 72551f0..9a3be19 100644
--- a/libc/bionic/__memset_chk.cpp
+++ b/libc/bionic/__memset_chk.cpp
@@ -41,11 +41,11 @@
* This memset check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-extern "C" void *__memset_chk (void *dest, int c, size_t n, size_t dest_len) {
- if (__predict_false(n > dest_len)) {
- __fortify_chk_fail("memset prevented write past end of buffer",
- BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW);
- }
+extern "C" void* __memset_chk (void* dest, int c, size_t n, size_t dest_len) {
+ if (__predict_false(n > dest_len)) {
+ __fortify_chk_fail("memset: prevented write past end of buffer",
+ BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW);
+ }
- return memset(dest, c, n);
+ return memset(dest, c, n);
}
diff --git a/libc/bionic/__read_chk.cpp b/libc/bionic/__read_chk.cpp
index 9de99c1..ff50983 100644
--- a/libc/bionic/__read_chk.cpp
+++ b/libc/bionic/__read_chk.cpp
@@ -32,11 +32,11 @@
extern "C" ssize_t __read_chk(int fd, void* buf, size_t count, size_t buf_size) {
if (__predict_false(count > buf_size)) {
- __fortify_chk_fail("read prevented write past end of buffer", 0);
+ __fortify_chk_fail("read: prevented write past end of buffer", 0);
}
if (__predict_false(count > SSIZE_MAX)) {
- __fortify_chk_fail("read count > SSIZE_MAX", 0);
+ __fortify_chk_fail("read: count > SSIZE_MAX", 0);
}
return read(fd, buf, count);
diff --git a/libc/bionic/__recvfrom_chk.cpp b/libc/bionic/__recvfrom_chk.cpp
index 00de1d9..48baa8e 100644
--- a/libc/bionic/__recvfrom_chk.cpp
+++ b/libc/bionic/__recvfrom_chk.cpp
@@ -34,10 +34,9 @@
extern "C"
ssize_t __recvfrom_chk(int socket, void* buf, size_t len, size_t buflen, unsigned int flags,
- const struct sockaddr* src_addr, socklen_t* addrlen)
-{
+ const struct sockaddr* src_addr, socklen_t* addrlen) {
if (__predict_false(len > buflen)) {
- __fortify_chk_fail("recvfrom prevented write past end of buffer", 0);
+ __fortify_chk_fail("recvfrom: prevented write past end of buffer", 0);
}
return recvfrom(socket, buf, len, flags, src_addr, addrlen);
diff --git a/libc/bionic/__strcat_chk.cpp b/libc/bionic/__strcat_chk.cpp
index f15cb5c..a0ab09e 100644
--- a/libc/bionic/__strcat_chk.cpp
+++ b/libc/bionic/__strcat_chk.cpp
@@ -41,24 +41,21 @@
* This strcat check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-extern "C" char* __strcat_chk(
- char* __restrict dest,
- const char* __restrict src,
- size_t dest_buf_size)
-{
- char* save = dest;
- size_t dest_len = __strlen_chk(dest, dest_buf_size);
+extern "C" char* __strcat_chk(char* __restrict dest, const char* __restrict src,
+ size_t dest_buf_size) {
+ char* save = dest;
+ size_t dest_len = __strlen_chk(dest, dest_buf_size);
- dest += dest_len;
- dest_buf_size -= dest_len;
+ dest += dest_len;
+ dest_buf_size -= dest_len;
- while ((*dest++ = *src++) != '\0') {
- dest_buf_size--;
- if (__predict_false(dest_buf_size == 0)) {
- __fortify_chk_fail("strcat prevented write past end of buffer",
- BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW);
- }
+ while ((*dest++ = *src++) != '\0') {
+ dest_buf_size--;
+ if (__predict_false(dest_buf_size == 0)) {
+ __fortify_chk_fail("strcat: prevented write past end of buffer",
+ BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW);
}
+ }
- return save;
+ return save;
}
diff --git a/libc/bionic/__strchr_chk.cpp b/libc/bionic/__strchr_chk.cpp
index 51d35d0..03b6b30 100644
--- a/libc/bionic/__strchr_chk.cpp
+++ b/libc/bionic/__strchr_chk.cpp
@@ -33,7 +33,7 @@
extern "C" char* __strchr_chk(const char* p, int ch, size_t s_len) {
for (;; ++p, s_len--) {
if (__predict_false(s_len == 0)) {
- __fortify_chk_fail("strchr prevented read past end of buffer", 0);
+ __fortify_chk_fail("strchr: prevented read past end of buffer", 0);
}
if (*p == static_cast<char>(ch)) {
return const_cast<char*>(p);
diff --git a/libc/bionic/__strcpy_chk.cpp b/libc/bionic/__strcpy_chk.cpp
index 9b39627..1f6bc80 100644
--- a/libc/bionic/__strcpy_chk.cpp
+++ b/libc/bionic/__strcpy_chk.cpp
@@ -41,13 +41,13 @@
* This strcpy check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-extern "C" char *__strcpy_chk (char *dest, const char *src, size_t dest_len) {
- // TODO: optimize so we don't scan src twice.
- size_t src_len = strlen(src) + 1;
- if (__predict_false(src_len > dest_len)) {
- __fortify_chk_fail("strcpy prevented write past end of buffer",
- BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW);
- }
+extern "C" char* __strcpy_chk (char* dest, const char* src, size_t dest_len) {
+ // TODO: optimize so we don't scan src twice.
+ size_t src_len = strlen(src) + 1;
+ if (__predict_false(src_len > dest_len)) {
+ __fortify_chk_fail("strcpy: prevented write past end of buffer",
+ BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW);
+ }
- return strcpy(dest, src);
+ return strcpy(dest, src);
}
diff --git a/libc/bionic/__strlcat_chk.cpp b/libc/bionic/__strlcat_chk.cpp
index 783dd84..f583154 100644
--- a/libc/bionic/__strlcat_chk.cpp
+++ b/libc/bionic/__strlcat_chk.cpp
@@ -42,12 +42,11 @@
* This strlcat check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-extern "C" size_t __strlcat_chk(char *dest, const char *src,
- size_t supplied_size, size_t dest_len_from_compiler)
-{
- if (__predict_false(supplied_size > dest_len_from_compiler)) {
- __fortify_chk_fail("strlcat prevented write past end of buffer", 0);
- }
+extern "C" size_t __strlcat_chk(char* dest, const char* src,
+ size_t supplied_size, size_t dest_len_from_compiler) {
+ if (__predict_false(supplied_size > dest_len_from_compiler)) {
+ __fortify_chk_fail("strlcat: prevented write past end of buffer", 0);
+ }
- return strlcat(dest, src, supplied_size);
+ return strlcat(dest, src, supplied_size);
}
diff --git a/libc/bionic/__strlcpy_chk.cpp b/libc/bionic/__strlcpy_chk.cpp
index 359e918..ebf1444 100644
--- a/libc/bionic/__strlcpy_chk.cpp
+++ b/libc/bionic/__strlcpy_chk.cpp
@@ -42,12 +42,11 @@
* This strlcpy check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-extern "C" size_t __strlcpy_chk(char *dest, const char *src,
- size_t supplied_size, size_t dest_len_from_compiler)
-{
- if (__predict_false(supplied_size > dest_len_from_compiler)) {
- __fortify_chk_fail("strlcpy prevented write past end of buffer", 0);
- }
+extern "C" size_t __strlcpy_chk(char* dest, const char* src,
+ size_t supplied_size, size_t dest_len_from_compiler) {
+ if (__predict_false(supplied_size > dest_len_from_compiler)) {
+ __fortify_chk_fail("strlcpy: prevented write past end of buffer", 0);
+ }
- return strlcpy(dest, src, supplied_size);
+ return strlcpy(dest, src, supplied_size);
}
diff --git a/libc/bionic/__strlen_chk.cpp b/libc/bionic/__strlen_chk.cpp
index d4c5e43..6621a6a 100644
--- a/libc/bionic/__strlen_chk.cpp
+++ b/libc/bionic/__strlen_chk.cpp
@@ -53,12 +53,12 @@
*
* or anytime strlen reads beyond an object boundary.
*/
-extern "C" size_t __strlen_chk(const char *s, size_t s_len) {
- size_t ret = strlen(s);
+extern "C" size_t __strlen_chk(const char* s, size_t s_len) {
+ size_t ret = strlen(s);
- if (__predict_false(ret >= s_len)) {
- __fortify_chk_fail("strlen prevented read past end of buffer", 0);
- }
+ if (__predict_false(ret >= s_len)) {
+ __fortify_chk_fail("strlen: prevented read past end of buffer", 0);
+ }
- return ret;
+ return ret;
}
diff --git a/libc/bionic/__strncat_chk.cpp b/libc/bionic/__strncat_chk.cpp
index cdb3c80..21e5e39 100644
--- a/libc/bionic/__strncat_chk.cpp
+++ b/libc/bionic/__strncat_chk.cpp
@@ -41,33 +41,30 @@
* This strncat check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-extern "C" char *__strncat_chk(
- char* __restrict dest,
- const char* __restrict src,
- size_t len, size_t dest_buf_size)
-{
- if (len == 0) {
- return dest;
- }
+extern "C" char* __strncat_chk(char* __restrict dest, const char* __restrict src,
+ size_t len, size_t dest_buf_size) {
+ if (len == 0) {
+ return dest;
+ }
- size_t dest_len = __strlen_chk(dest, dest_buf_size);
- char *d = dest + dest_len;
- dest_buf_size -= dest_len;
+ size_t dest_len = __strlen_chk(dest, dest_buf_size);
+ char *d = dest + dest_len;
+ dest_buf_size -= dest_len;
- while (*src != '\0') {
- *d++ = *src++;
- len--; dest_buf_size--;
+ while (*src != '\0') {
+ *d++ = *src++;
+ len--; dest_buf_size--;
- if (__predict_false(dest_buf_size == 0)) {
- __fortify_chk_fail("strncat prevented write past end of buffer",
- BIONIC_EVENT_STRNCAT_BUFFER_OVERFLOW);
- }
+ if (__predict_false(dest_buf_size == 0)) {
+ __fortify_chk_fail("strncat: prevented write past end of buffer",
+ BIONIC_EVENT_STRNCAT_BUFFER_OVERFLOW);
+ }
- if (len == 0) {
- break;
- }
+ if (len == 0) {
+ break;
}
+ }
- *d = '\0';
- return dest;
+ *d = '\0';
+ return dest;
}
diff --git a/libc/bionic/__strncpy_chk.cpp b/libc/bionic/__strncpy_chk.cpp
index d0e9013..76458aa 100644
--- a/libc/bionic/__strncpy_chk.cpp
+++ b/libc/bionic/__strncpy_chk.cpp
@@ -42,10 +42,9 @@
* greater than 0.
*/
extern "C" char* __strncpy_chk(char* __restrict dest, const char* __restrict src,
- size_t len, size_t dest_len)
-{
+ size_t len, size_t dest_len) {
if (__predict_false(len > dest_len)) {
- __fortify_chk_fail("strncpy prevented write past end of buffer",
+ __fortify_chk_fail("strncpy: prevented write past end of buffer",
BIONIC_EVENT_STRNCPY_BUFFER_OVERFLOW);
}
@@ -64,7 +63,7 @@ extern "C" char* __strncpy_chk2(char* __restrict dst, const char* __restrict src
size_t n, size_t dest_len, size_t src_len)
{
if (__predict_false(n > dest_len)) {
- __fortify_chk_fail("strncpy prevented write past end of buffer",
+ __fortify_chk_fail("strncpy: prevented write past end of buffer",
BIONIC_EVENT_STRNCPY_BUFFER_OVERFLOW);
}
if (n != 0) {
@@ -83,7 +82,7 @@ extern "C" char* __strncpy_chk2(char* __restrict dst, const char* __restrict src
size_t s_copy_len = static_cast<size_t>(s - src);
if (__predict_false(s_copy_len > src_len)) {
- __fortify_chk_fail("strncpy prevented read past end of buffer", 0);
+ __fortify_chk_fail("strncpy: prevented read past end of buffer", 0);
}
}
diff --git a/libc/bionic/__strrchr_chk.cpp b/libc/bionic/__strrchr_chk.cpp
index fe56c9a..4037207 100644
--- a/libc/bionic/__strrchr_chk.cpp
+++ b/libc/bionic/__strrchr_chk.cpp
@@ -31,17 +31,17 @@
#include <string.h>
#include "private/libc_logging.h"
-extern "C" char* __strrchr_chk(const char *p, int ch, size_t s_len)
-{
- char *save;
-
- for (save = NULL;; ++p, s_len--) {
- if (s_len == 0)
- __fortify_chk_fail("strrchr prevented read past end of buffer", 0);
- if (*p == (char) ch)
- save = (char *)p;
- if (!*p)
- return(save);
+extern "C" char* __strrchr_chk(const char *p, int ch, size_t s_len) {
+ for (char* save = NULL;; ++p, s_len--) {
+ if (s_len == 0) {
+ __fortify_chk_fail("strrchr: prevented read past end of buffer", 0);
+ }
+ if (*p == (char) ch) {
+ save = (char *)p;
+ }
+ if (!*p) {
+ return(save);
}
- /* NOTREACHED */
+ }
+ /* NOTREACHED */
}
diff --git a/libc/bionic/__umask_chk.cpp b/libc/bionic/__umask_chk.cpp
index 7d2a99a..33b7121 100644
--- a/libc/bionic/__umask_chk.cpp
+++ b/libc/bionic/__umask_chk.cpp
@@ -43,9 +43,9 @@
* greater than 0.
*/
extern "C" mode_t __umask_chk(mode_t mode) {
- if (__predict_false((mode & 0777) != mode)) {
- __fortify_chk_fail("umask called with invalid mask", 0);
- }
+ if (__predict_false((mode & 0777) != mode)) {
+ __fortify_chk_fail("umask: called with invalid mask", 0);
+ }
- return umask(mode);
+ return umask(mode);
}
diff --git a/libc/bionic/__vsnprintf_chk.cpp b/libc/bionic/__vsnprintf_chk.cpp
index a03d12f..ecf5816 100644
--- a/libc/bionic/__vsnprintf_chk.cpp
+++ b/libc/bionic/__vsnprintf_chk.cpp
@@ -42,19 +42,13 @@
* This vsnprintf check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-extern "C" int __vsnprintf_chk(
- char *dest,
- size_t supplied_size,
- int /*flags*/,
- size_t dest_len_from_compiler,
- const char *format,
- va_list va)
-{
- if (__predict_false(supplied_size > dest_len_from_compiler)) {
- __fortify_chk_fail("vsnprintf prevented write past end of buffer", 0);
- }
+extern "C" int __vsnprintf_chk(char* dest, size_t supplied_size, int /*flags*/,
+ size_t dest_len_from_compiler, const char* format, va_list va) {
+ if (__predict_false(supplied_size > dest_len_from_compiler)) {
+ __fortify_chk_fail("vsnprintf: prevented write past end of buffer", 0);
+ }
- return vsnprintf(dest, supplied_size, format, va);
+ return vsnprintf(dest, supplied_size, format, va);
}
/*
@@ -68,20 +62,11 @@ extern "C" int __vsnprintf_chk(
* This snprintf check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-extern "C" int __snprintf_chk(
- char *dest,
- size_t supplied_size,
- int flags,
- size_t dest_len_from_compiler,
- const char *format, ...)
-{
- va_list va;
- int retval;
-
- va_start(va, format);
- retval = __vsnprintf_chk(dest, supplied_size, flags,
- dest_len_from_compiler, format, va);
- va_end(va);
-
- return retval;
+extern "C" int __snprintf_chk(char* dest, size_t supplied_size, int flags,
+ size_t dest_len_from_compiler, const char* format, ...) {
+ va_list va;
+ va_start(va, format);
+ int result = __vsnprintf_chk(dest, supplied_size, flags, dest_len_from_compiler, format, va);
+ va_end(va);
+ return result;
}
diff --git a/libc/bionic/__vsprintf_chk.cpp b/libc/bionic/__vsprintf_chk.cpp
index 3810694..feb6e68 100644
--- a/libc/bionic/__vsprintf_chk.cpp
+++ b/libc/bionic/__vsprintf_chk.cpp
@@ -42,20 +42,13 @@
* This vsprintf check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-extern "C" int __vsprintf_chk(
- char *dest,
- int /*flags*/,
- size_t dest_len_from_compiler,
- const char *format,
- va_list va)
-{
- int ret = vsnprintf(dest, dest_len_from_compiler, format, va);
-
- if ((size_t) ret >= dest_len_from_compiler) {
- __fortify_chk_fail("vsprintf prevented write past end of buffer", 0);
- }
-
- return ret;
+extern "C" int __vsprintf_chk(char* dest, int /*flags*/,
+ size_t dest_len_from_compiler, const char* format, va_list va) {
+ int result = vsnprintf(dest, dest_len_from_compiler, format, va);
+ if ((size_t) result >= dest_len_from_compiler) {
+ __fortify_chk_fail("vsprintf: prevented write past end of buffer", 0);
+ }
+ return result;
}
/*
@@ -69,19 +62,11 @@ extern "C" int __vsprintf_chk(
* This sprintf check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-extern "C" int __sprintf_chk(
- char *dest,
- int flags,
- size_t dest_len_from_compiler,
- const char *format, ...)
-{
- va_list va;
- int retval;
-
- va_start(va, format);
- retval = __vsprintf_chk(dest, flags,
- dest_len_from_compiler, format, va);
- va_end(va);
-
- return retval;
+extern "C" int __sprintf_chk(char* dest, int flags,
+ size_t dest_len_from_compiler, const char* format, ...) {
+ va_list va;
+ va_start(va, format);
+ int result = __vsprintf_chk(dest, flags, dest_len_from_compiler, format, va);
+ va_end(va);
+ return result;
}
diff --git a/libc/bionic/libc_logging.cpp b/libc/bionic/libc_logging.cpp
index c7eca8a..2d00596 100644
--- a/libc/bionic/libc_logging.cpp
+++ b/libc/bionic/libc_logging.cpp
@@ -504,7 +504,7 @@ void __libc_android_log_event_uid(int32_t tag) {
__libc_android_log_event_int(tag, getuid());
}
-void __fortify_chk_fail(const char *msg, uint32_t tag) {
+void __fortify_chk_fail(const char* msg, uint32_t tag) {
if (tag != 0) {
__libc_android_log_event_uid(tag);
}
diff --git a/libc/bionic/open.c b/libc/bionic/open.c
index cde3029..6441dc2 100644
--- a/libc/bionic/open.c
+++ b/libc/bionic/open.c
@@ -33,30 +33,27 @@
extern int __open(const char*, int, int);
-int open(const char *pathname, int flags, ...)
-{
- mode_t mode = 0;
+int open(const char* pathname, int flags, ...) {
+ mode_t mode = 0;
- flags |= O_LARGEFILE;
+ flags |= O_LARGEFILE;
- if (flags & O_CREAT)
- {
- va_list args;
+ if (flags & O_CREAT) {
+ va_list args;
+ va_start(args, flags);
+ mode = (mode_t) va_arg(args, int);
+ va_end(args);
+ }
- va_start(args, flags);
- mode = (mode_t) va_arg(args, int);
- va_end(args);
- }
-
- return __open(pathname, flags, mode);
+ return __open(pathname, flags, mode);
}
-int __open_2(const char *pathname, int flags) {
- if (__predict_false(flags & O_CREAT)) {
- __fortify_chk_fail("open(O_CREAT) called without specifying a mode", 0);
- }
+int __open_2(const char* pathname, int flags) {
+ if (__predict_false(flags & O_CREAT)) {
+ __fortify_chk_fail("open(O_CREAT): called without specifying a mode", 0);
+ }
- flags |= O_LARGEFILE;
+ flags |= O_LARGEFILE;
- return __open(pathname, flags, 0);
+ return __open(pathname, flags, 0);
}
diff --git a/libc/bionic/openat.c b/libc/bionic/openat.c
index b8c887e..56bb627 100644
--- a/libc/bionic/openat.c
+++ b/libc/bionic/openat.c
@@ -33,31 +33,27 @@
extern int __openat(int, const char*, int, int);
-int openat(int fd, const char *pathname, int flags, ...)
-{
- mode_t mode = 0;
+int openat(int fd, const char *pathname, int flags, ...) {
+ mode_t mode = 0;
- flags |= O_LARGEFILE;
+ flags |= O_LARGEFILE;
- if (flags & O_CREAT)
- {
- va_list args;
+ if (flags & O_CREAT) {
+ va_list args;
+ va_start(args, flags);
+ mode = (mode_t) va_arg(args, int);
+ va_end(args);
+ }
- va_start(args, flags);
- mode = (mode_t) va_arg(args, int);
- va_end(args);
- }
-
- return __openat(fd, pathname, flags, mode);
+ return __openat(fd, pathname, flags, mode);
}
-int __openat_2(int fd, const char *pathname, int flags)
-{
- if (flags & O_CREAT) {
- __fortify_chk_fail("openat(O_CREAT) called without specifying a mode", 0);
- }
+int __openat_2(int fd, const char* pathname, int flags) {
+ if (flags & O_CREAT) {
+ __fortify_chk_fail("openat(O_CREAT): called without specifying a mode", 0);
+ }
- flags |= O_LARGEFILE;
+ flags |= O_LARGEFILE;
- return __openat(fd, pathname, flags, 0);
+ return __openat(fd, pathname, flags, 0);
}