Merge "Improve diagnostics from the assembler __strcpy_chk routines."
This commit is contained in:
commit
2f82dc50ed
5 changed files with 28 additions and 65 deletions
|
@ -147,23 +147,15 @@ ENTRY(__strcpy_chk)
|
||||||
pld [r1, #0]
|
pld [r1, #0]
|
||||||
pld [r1, #64]
|
pld [r1, #64]
|
||||||
ldr r0, [sp]
|
ldr r0, [sp]
|
||||||
cmp r3, lr
|
|
||||||
bhs .L_strcpy_chk_failed
|
|
||||||
|
|
||||||
// Add 1 for copy length to get the string terminator.
|
// Add 1 for copy length to get the string terminator.
|
||||||
add r2, r3, #1
|
add r2, r3, #1
|
||||||
|
|
||||||
|
cmp r2, lr
|
||||||
|
itt hi
|
||||||
|
movhi r0, r2
|
||||||
|
bhi __strcpy_chk_fail
|
||||||
|
|
||||||
#include MEMCPY_BASE
|
#include MEMCPY_BASE
|
||||||
|
|
||||||
.L_strcpy_chk_failed:
|
|
||||||
ldr r0, error_message
|
|
||||||
1:
|
|
||||||
add r0, pc
|
|
||||||
bl __fortify_fatal
|
|
||||||
error_message:
|
|
||||||
.word error_string-(1b+4)
|
|
||||||
END(__strcpy_chk)
|
END(__strcpy_chk)
|
||||||
|
|
||||||
.data
|
|
||||||
error_string:
|
|
||||||
.string "strcpy: prevented write past end of buffer"
|
|
||||||
|
|
|
@ -149,33 +149,18 @@ ENTRY(__strcpy_chk)
|
||||||
pld [r1, #0]
|
pld [r1, #0]
|
||||||
pld [r1, #64]
|
pld [r1, #64]
|
||||||
ldr r0, [sp]
|
ldr r0, [sp]
|
||||||
cmp r3, lr
|
|
||||||
bhs __strcpy_chk_fail
|
|
||||||
|
|
||||||
// Add 1 for copy length to get the string terminator.
|
// Add 1 for copy length to get the string terminator.
|
||||||
add r2, r3, #1
|
add r2, r3, #1
|
||||||
|
|
||||||
|
cmp r2, lr
|
||||||
|
itt hi
|
||||||
|
movhi r0, r2
|
||||||
|
bhi __strcpy_chk_fail
|
||||||
|
|
||||||
// Fall through into the memcpy_base function.
|
// Fall through into the memcpy_base function.
|
||||||
END(__strcpy_chk)
|
END(__strcpy_chk)
|
||||||
|
|
||||||
#define MEMCPY_BASE __strcpy_chk_memcpy_base
|
#define MEMCPY_BASE __strcpy_chk_memcpy_base
|
||||||
#define MEMCPY_BASE_ALIGNED __strcpy_chk_memcpy_base_aligned
|
#define MEMCPY_BASE_ALIGNED __strcpy_chk_memcpy_base_aligned
|
||||||
#include "memcpy_base.S"
|
#include "memcpy_base.S"
|
||||||
|
|
||||||
ENTRY_PRIVATE(__strcpy_chk_fail)
|
|
||||||
.cfi_def_cfa_offset 8
|
|
||||||
.cfi_rel_offset r0, 0
|
|
||||||
.cfi_rel_offset lr, 4
|
|
||||||
|
|
||||||
ldr r0, error_message
|
|
||||||
1:
|
|
||||||
add r0, pc
|
|
||||||
bl __fortify_fatal
|
|
||||||
|
|
||||||
error_message:
|
|
||||||
.word error_string-(1b+4)
|
|
||||||
END(__strcpy_chk_fail)
|
|
||||||
|
|
||||||
.data
|
|
||||||
error_string:
|
|
||||||
.string "strcpy: prevented write past end of buffer"
|
|
||||||
|
|
|
@ -147,30 +147,18 @@ ENTRY(__strcpy_chk)
|
||||||
pld [r1, #0]
|
pld [r1, #0]
|
||||||
pld [r1, #64]
|
pld [r1, #64]
|
||||||
ldr r0, [sp]
|
ldr r0, [sp]
|
||||||
cmp r3, lr
|
|
||||||
bhs __strcpy_chk_failed
|
|
||||||
|
|
||||||
// Add 1 for copy length to get the string terminator.
|
// Add 1 for copy length to get the string terminator.
|
||||||
add r2, r3, #1
|
add r2, r3, #1
|
||||||
|
|
||||||
|
cmp r2, lr
|
||||||
|
itt hi
|
||||||
|
movhi r0, r2
|
||||||
|
bhi __strcpy_chk_fail
|
||||||
|
|
||||||
|
// Fall through into the memcpy_base function.
|
||||||
END(__strcpy_chk)
|
END(__strcpy_chk)
|
||||||
|
|
||||||
#define MEMCPY_BASE __strcpy_chk_memcpy_base
|
#define MEMCPY_BASE __strcpy_chk_memcpy_base
|
||||||
#define MEMCPY_BASE_ALIGNED __strcpy_chk_memcpy_base_aligned
|
#define MEMCPY_BASE_ALIGNED __strcpy_chk_memcpy_base_aligned
|
||||||
#include "memcpy_base.S"
|
#include "memcpy_base.S"
|
||||||
|
|
||||||
ENTRY_PRIVATE(__strcpy_chk_failed)
|
|
||||||
.cfi_def_cfa_offset 8
|
|
||||||
.cfi_rel_offset r0, 0
|
|
||||||
.cfi_rel_offset lr, 4
|
|
||||||
|
|
||||||
ldr r0, error_message
|
|
||||||
1:
|
|
||||||
add r0, pc
|
|
||||||
bl __fortify_fatal
|
|
||||||
error_message:
|
|
||||||
.word error_string-(1b+4)
|
|
||||||
END(__strcpy_chk_failed)
|
|
||||||
|
|
||||||
.data
|
|
||||||
error_string:
|
|
||||||
.string "strcpy: prevented write past end of buffer"
|
|
||||||
|
|
|
@ -147,23 +147,15 @@ ENTRY(__strcpy_chk)
|
||||||
pld [r1, #0]
|
pld [r1, #0]
|
||||||
pld [r1, #64]
|
pld [r1, #64]
|
||||||
ldr r0, [sp]
|
ldr r0, [sp]
|
||||||
cmp r3, lr
|
|
||||||
bhs .L_strcpy_chk_failed
|
|
||||||
|
|
||||||
// Add 1 for copy length to get the string terminator.
|
// Add 1 for copy length to get the string terminator.
|
||||||
add r2, r3, #1
|
add r2, r3, #1
|
||||||
|
|
||||||
|
cmp r2, lr
|
||||||
|
itt hi
|
||||||
|
movhi r0, r2
|
||||||
|
bhi __strcpy_chk_fail
|
||||||
|
|
||||||
#include "memcpy_base.S"
|
#include "memcpy_base.S"
|
||||||
|
|
||||||
.L_strcpy_chk_failed:
|
|
||||||
ldr r0, error_message
|
|
||||||
1:
|
|
||||||
add r0, pc
|
|
||||||
bl __fortify_fatal
|
|
||||||
error_message:
|
|
||||||
.word error_string-(1b+4)
|
|
||||||
END(__strcpy_chk)
|
END(__strcpy_chk)
|
||||||
|
|
||||||
.data
|
|
||||||
error_string:
|
|
||||||
.string "strcpy: prevented write past end of buffer"
|
|
||||||
|
|
|
@ -288,6 +288,12 @@ char* __strchr_chk(const char* p, int ch, size_t s_len) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// strcpy is performance-critical enough that we have assembler __strcpy_chk implementations.
|
||||||
|
// This function is used to give better diagnostics than we can easily do from assembler.
|
||||||
|
extern "C" void __strcpy_chk_fail(size_t dst_buf_size) {
|
||||||
|
__fortify_fatal("strcpy: prevented write past end of %zu-byte buffer", dst_buf_size);
|
||||||
|
}
|
||||||
|
|
||||||
size_t __strlcat_chk(char* dst, const char* src,
|
size_t __strlcat_chk(char* dst, const char* src,
|
||||||
size_t supplied_size, size_t dst_len_from_compiler) {
|
size_t supplied_size, size_t dst_len_from_compiler) {
|
||||||
__check_buffer_access("strlcat", "write into", supplied_size, dst_len_from_compiler);
|
__check_buffer_access("strlcat", "write into", supplied_size, dst_len_from_compiler);
|
||||||
|
|
Loading…
Reference in a new issue