
11b3a0c2c5db
115412c37195
#explicit zero 1131456ac632
#brk 1158ebc243ea
#random 115323b39f7e
#undefined 116a91d9dddb
#merge 11a042b5a0ba
#vla formatting 119ec639de1b
#pthread 1149571a0a49
#read only 11149cc5ccb8
#zero 112e613ccbe7
#fork mmap 11e239c7dff8
#memprot pthread 110b03d92b7f
#xor 11de08419b82
#junk 11897d4903e2
#guard 11648cd68ca3
#ptrhread guard 110bc4dbcbd2
#stack rand 10aa9cc05d07
10a8cdbb6352
#explicit zero 10b28302c668
#brk 109f8be7d07c
#random 10cb91a7ee3a
#undefined 1008279e2fdd
#merge 106a18bd565d
#vla formatting 102f392c2d08
#pthread 108bbce1bc50
#read only 10725f61db82
#zero 104cd257135f
#fork mmap 109220cf622b
#memprot pthread 108ef71d1ffd
#memprot exit 100eaef1abbd
#xor 1064f1cc2148
#junk 105c42a527cf
#guard 105cc8c34e60
#pthread guard 107f61cc8a1c
#stack rand 9abdf523d26
9e4b9b31e6f
#explicit zero 9a3a22a63d2
#brk 97444dbc3cf
#random 9dcd3b72ac9
#undefined 9543e1df342
#merge 9611e5691f7
#vla formatting 98de97ce864
#pthread 9a475717042
#read only 97f0947cc0e
#zero 9e9751d3370
#fork mmap 983cd86d0d5
#memprot pthread 91ebb165455
#memprot exit 9488ba483cf
#xor 9f9351d884b
#junk 985e5bca0a5
#move Signed-off-by: Tad <tad@spotco.us>
77 lines
2.2 KiB
Diff
77 lines
2.2 KiB
Diff
From 31456ac632903235e14500af8b5d7dff2d25d724 Mon Sep 17 00:00:00 2001
|
|
From: Daniel Micay <danielmicay@gmail.com>
|
|
Date: Sun, 8 Feb 2015 01:18:54 -0500
|
|
Subject: [PATCH] replace brk and sbrk with stubs
|
|
|
|
Pretend that there is never room to grow the heap in order to prevent
|
|
usage of these unsafe legacy functions. There are likely no users of
|
|
these in practice as it is inherently broken to use them outside of
|
|
malloc.
|
|
|
|
Signed-off-by: anupritaisno1 <www.anuprita804@gmail.com>
|
|
---
|
|
libc/bionic/brk.cpp | 48 ++++++++-------------------------------------
|
|
1 file changed, 8 insertions(+), 40 deletions(-)
|
|
|
|
diff --git a/libc/bionic/brk.cpp b/libc/bionic/brk.cpp
|
|
index 566c33a7a6..ef93055139 100644
|
|
--- a/libc/bionic/brk.cpp
|
|
+++ b/libc/bionic/brk.cpp
|
|
@@ -29,48 +29,16 @@
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
|
|
-#if defined(__LP64__)
|
|
-static void* __bionic_brk;
|
|
-#else
|
|
-void* __bionic_brk; // Accidentally exported by the NDK.
|
|
+#if !defined(__LP64__)
|
|
+void* __bionic_brk = reinterpret_cast<void*>(-1); // Accidentally exported by the NDK.
|
|
#endif
|
|
|
|
-extern "C" void* __brk(void* __addr);
|
|
-
|
|
-int brk(void* end_data) {
|
|
- __bionic_brk = __brk(end_data);
|
|
- if (__bionic_brk < end_data) {
|
|
- errno = ENOMEM;
|
|
- return -1;
|
|
- }
|
|
- return 0;
|
|
+int brk(void*) {
|
|
+ errno = ENOMEM;
|
|
+ return -1;
|
|
}
|
|
|
|
-void* sbrk(ptrdiff_t increment) {
|
|
- // Initialize __bionic_brk if necessary.
|
|
- if (__bionic_brk == nullptr) {
|
|
- __bionic_brk = __brk(nullptr);
|
|
- }
|
|
-
|
|
- // Don't ask the kernel if we already know the answer.
|
|
- if (increment == 0) {
|
|
- return __bionic_brk;
|
|
- }
|
|
-
|
|
- // Avoid overflow.
|
|
- uintptr_t old_brk = reinterpret_cast<uintptr_t>(__bionic_brk);
|
|
- if ((increment > 0 && static_cast<uintptr_t>(increment) > (UINTPTR_MAX - old_brk)) ||
|
|
- (increment < 0 && static_cast<uintptr_t>(-increment) > old_brk)) {
|
|
- errno = ENOMEM;
|
|
- return reinterpret_cast<void*>(-1);
|
|
- }
|
|
-
|
|
- void* desired_brk = reinterpret_cast<void*>(old_brk + increment);
|
|
- __bionic_brk = __brk(desired_brk);
|
|
- if (__bionic_brk < desired_brk) {
|
|
- errno = ENOMEM;
|
|
- return reinterpret_cast<void*>(-1);
|
|
- }
|
|
-
|
|
- return reinterpret_cast<void*>(old_brk);
|
|
+void* sbrk(ptrdiff_t) {
|
|
+ errno = ENOMEM;
|
|
+ return reinterpret_cast<void*>(-1);
|
|
}
|