summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libc/arch-arm/cortex-a15/bionic/__strcat_chk_common.S15
-rw-r--r--libc/arch-arm/cortex-a9/bionic/__strcat_chk.S22
-rw-r--r--libc/arch-arm/denver/bionic/__strcat_chk.S24
-rw-r--r--libc/arch-arm/krait/bionic/__strcat_chk.S15
-rw-r--r--libc/bionic/fortify.cpp6
5 files changed, 17 insertions, 65 deletions
diff --git a/libc/arch-arm/cortex-a15/bionic/__strcat_chk_common.S b/libc/arch-arm/cortex-a15/bionic/__strcat_chk_common.S
index 020ce4226..a610dd5b4 100644
--- a/libc/arch-arm/cortex-a15/bionic/__strcat_chk_common.S
+++ b/libc/arch-arm/cortex-a15/bionic/__strcat_chk_common.S
@@ -176,7 +176,9 @@ ENTRY(__strcat_chk)
.L_strlen_done:
add r2, r3, r4
cmp r2, lr
- bhi .L_strcat_chk_failed
+ itt hi
+ movhi r0, lr
+ bhi __strcat_chk_fail
// Set up the registers for the memcpy code.
mov r1, r5
@@ -194,15 +196,4 @@ ENTRY(__strcat_chk)
.cfi_adjust_cfa_offset 8
.cfi_rel_offset r4, 0
.cfi_rel_offset r5, 4
-.L_strcat_chk_failed:
- ldr r0, error_message
-1:
- add r0, pc
- bl __fortify_fatal
-error_message:
- .word error_string-(1b+4)
END(__strcat_chk)
-
- .data
-error_string:
- .string "strcat: prevented write past end of buffer"
diff --git a/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
index 6245861a1..776c78256 100644
--- a/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
+++ b/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
@@ -179,6 +179,8 @@ ENTRY(__strcat_chk)
.L_strlen_done:
add r2, r3, r4
cmp r2, lr
+ itt hi
+ movhi r0, lr
bhi __strcat_chk_fail
// Set up the registers for the memcpy code.
@@ -194,23 +196,3 @@ END(__strcat_chk)
#define MEMCPY_BASE __strcat_chk_memcpy_base
#define MEMCPY_BASE_ALIGNED __strcat_chk_memcpy_base_aligned
#include "memcpy_base.S"
-
-ENTRY_PRIVATE(__strcat_chk_fail)
- .cfi_def_cfa_offset 8
- .cfi_rel_offset r0, 0
- .cfi_rel_offset lr, 4
- .cfi_adjust_cfa_offset 8
- .cfi_rel_offset r4, 0
- .cfi_rel_offset r5, 4
-
- ldr r0, error_message
-1:
- add r0, pc
- bl __fortify_fatal
-error_message:
- .word error_string-(1b+4)
-END(__strcat_chk_fail)
-
- .data
-error_string:
- .string "strcat: prevented write past end of buffer"
diff --git a/libc/arch-arm/denver/bionic/__strcat_chk.S b/libc/arch-arm/denver/bionic/__strcat_chk.S
index 2fbf5d6f0..9f7db59dd 100644
--- a/libc/arch-arm/denver/bionic/__strcat_chk.S
+++ b/libc/arch-arm/denver/bionic/__strcat_chk.S
@@ -176,7 +176,9 @@ ENTRY(__strcat_chk)
.L_strlen_done:
add r2, r3, r4
cmp r2, lr
- bhi __strcat_chk_failed
+ itt hi
+ movhi r0, lr
+ bhi __strcat_chk_fail
// Set up the registers for the memcpy code.
mov r1, r5
@@ -190,23 +192,3 @@ END(__strcat_chk)
#define MEMCPY_BASE_ALIGNED __strcat_chk_memcpy_base_aligned
#include "memcpy_base.S"
-
-ENTRY_PRIVATE(__strcat_chk_failed)
- .cfi_def_cfa_offset 8
- .cfi_rel_offset r0, 0
- .cfi_rel_offset lr, 4
- .cfi_adjust_cfa_offset 8
- .cfi_rel_offset r4, 0
- .cfi_rel_offset r5, 4
-
- ldr r0, error_message
-1:
- add r0, pc
- bl __fortify_fatal
-error_message:
- .word error_string-(1b+4)
-END(__strcat_chk_failed)
-
- .data
-error_string:
- .string "strcat: prevented write past end of buffer"
diff --git a/libc/arch-arm/krait/bionic/__strcat_chk.S b/libc/arch-arm/krait/bionic/__strcat_chk.S
index fabca2498..a46ff9800 100644
--- a/libc/arch-arm/krait/bionic/__strcat_chk.S
+++ b/libc/arch-arm/krait/bionic/__strcat_chk.S
@@ -176,7 +176,9 @@ ENTRY(__strcat_chk)
.L_strlen_done:
add r2, r3, r4
cmp r2, lr
- bhi .L_strcat_chk_failed
+ itt hi
+ movhi r0, lr
+ bhi __strcat_chk_fail
// Set up the registers for the memcpy code.
mov r1, r5
@@ -194,15 +196,4 @@ ENTRY(__strcat_chk)
.cfi_adjust_cfa_offset 8
.cfi_rel_offset r4, 0
.cfi_rel_offset r5, 4
-.L_strcat_chk_failed:
- ldr r0, error_message
-1:
- add r0, pc
- bl __fortify_fatal
-error_message:
- .word error_string-(1b+4)
END(__strcat_chk)
-
- .data
-error_string:
- .string "strcat: prevented write past end of buffer"
diff --git a/libc/bionic/fortify.cpp b/libc/bionic/fortify.cpp
index ad7aa04f3..278c606e1 100644
--- a/libc/bionic/fortify.cpp
+++ b/libc/bionic/fortify.cpp
@@ -268,6 +268,12 @@ char* __stpncpy_chk2(char* __restrict dst, const char* __restrict src,
return dst;
}
+// strcat is performance-critical enough that we have assembler __strcat_chk implementations.
+// This function is used to give better diagnostics than we can easily do from assembler.
+extern "C" void __strcat_chk_fail(size_t dst_buf_size) {
+ __fortify_fatal("strcat: prevented write past end of %zu-byte buffer", dst_buf_size);
+}
+
char* __strchr_chk(const char* p, int ch, size_t s_len) {
for (;; ++p, s_len--) {
if (__predict_false(s_len == 0)) {