aboutsummaryrefslogtreecommitdiffstats
path: root/libc/string/memmove.c
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2012-07-12 15:10:03 -0700
committerNick Kralevich <nnk@google.com>2012-07-12 15:38:15 -0700
commitf3913b5b68347ce9a4cb17977df2c33f1e8f6000 (patch)
treefae959e2f8c146b61eb43af80d9ae4918640d2c0 /libc/string/memmove.c
parent86a4fca0b473c49bcbcf2deb6b5822aa9ab9631e (diff)
downloadandroid_bionic-f3913b5b68347ce9a4cb17977df2c33f1e8f6000.tar.gz
android_bionic-f3913b5b68347ce9a4cb17977df2c33f1e8f6000.tar.bz2
android_bionic-f3913b5b68347ce9a4cb17977df2c33f1e8f6000.zip
FORTIFY_SOURCE: enhanced memcpy protections.
Two changes: 1) Detect memory read overruns. For example: int main() { char buf[10]; memcpy(buf, "abcde", sizeof(buf)); sprintf("%s\n", buf); } because "abcde" is only 6 bytes, copying 10 bytes from it is a bug. This particular bug will be detected at compile time. Other similar bugs may be detected at runtime. 2) Detect overlapping buffers on memcpy() It is a bug to call memcpy() on buffers which overlap. For example, the following code is buggy: char buf3[0x800]; char *first_half = &buf3[0x400]; char *second_half = &buf3[1]; memset(buf3, 0, sizeof(buf3)); memcpy(first_half, second_half, 0x400); printf("1: %s\n", buf3); We now detect this at compile and run time. Change-Id: I092bd89f11f18e08e8a9dda0ca903aaea8e06d91
Diffstat (limited to 'libc/string/memmove.c')
-rw-r--r--libc/string/memmove.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/libc/string/memmove.c b/libc/string/memmove.c
index fb1d9753e..a9fc1b53a 100644
--- a/libc/string/memmove.c
+++ b/libc/string/memmove.c
@@ -25,6 +25,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+#undef _FORTIFY_SOURCE
#include <string.h>
#include <strings.h>