Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc memcpy/memmove/bcopy: Add diagnostic code to check ...
details: https://anonhg.NetBSD.org/src/rev/1afa8dc5d6af
branches: trunk
changeset: 533579:1afa8dc5d6af
user: kent <kent%NetBSD.org@localhost>
date: Thu Jul 04 15:48:40 2002 +0000
description:
memcpy/memmove/bcopy: Add diagnostic code to check pointer wraparound.
The code is enabled only when _DIAGNOSTIC is defined.
diffstat:
lib/libc/arch/i386/string/bcopy.S | 43 ++++++++++++++++++++++++++++++++++++++-
lib/libc/string/bcopy.c | 6 +++-
2 files changed, 46 insertions(+), 3 deletions(-)
diffs (98 lines):
diff -r 6fd9b8a4f16c -r 1afa8dc5d6af lib/libc/arch/i386/string/bcopy.S
--- a/lib/libc/arch/i386/string/bcopy.S Thu Jul 04 14:37:10 2002 +0000
+++ b/lib/libc/arch/i386/string/bcopy.S Thu Jul 04 15:48:40 2002 +0000
@@ -36,7 +36,7 @@
#include <machine/asm.h>
#if defined(LIBC_SCCS)
- RCSID("$NetBSD: bcopy.S,v 1.6 1996/11/12 00:50:06 jtc Exp $")
+ RCSID("$NetBSD: bcopy.S,v 1.7 2002/07/04 15:48:40 kent Exp $")
#endif
/*
@@ -84,6 +84,29 @@
1:
addl %ecx,%edi /* copy backwards. */
addl %ecx,%esi
+#ifdef _DIAGNOSTIC
+#define _DIAGASSERT call _C_LABEL(__diagassert13)
+ cmpl 12(%esp),%edi /* check pointer wraparound */
+ jae 2f
+ pushl $diagmes1
+ pushl $func
+ pushl $__LINE__-4
+ pushl $file
+ _DIAGASSERT
+ addl $16,%esp
+ jmp 4f
+2:
+ cmpl 16(%esp),%esi
+ jae 3f
+ pushl $diagmes2
+ pushl $func
+ pushl $__LINE__-4
+ pushl $file
+ _DIAGASSERT
+ addl $16,%esp
+ jmp 4f
+3:
+#endif
std
andl $3,%ecx /* any fractional bytes? */
decl %edi
@@ -96,6 +119,7 @@
subl $3,%edi
rep
movsl
+4:
#if defined(MEMCOPY) || defined(MEMMOVE)
movl 12(%esp),%eax
#endif
@@ -103,3 +127,20 @@
popl %esi
cld
ret
+
+#ifdef _DIAGNOSTIC
+file:
+ .asciz __FILE__
+func:
+#if defined(MEMCOPY)
+ .asciz "memcpy"
+#elseif defined(MEMMOVE)
+ .asciz "memmove"
+#else
+ .asciz "bcopy"
+#endif
+diagmes1:
+ .asciz "src + length > src"
+diagmes2:
+ .asciz "dst + length > dst"
+#endif /* _DIAGNOSTIC */
diff -r 6fd9b8a4f16c -r 1afa8dc5d6af lib/libc/string/bcopy.c
--- a/lib/libc/string/bcopy.c Thu Jul 04 14:37:10 2002 +0000
+++ b/lib/libc/string/bcopy.c Thu Jul 04 15:48:40 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcopy.c,v 1.13 2001/02/08 18:33:50 wiz Exp $ */
+/* $NetBSD: bcopy.c,v 1.14 2002/07/04 15:48:41 kent Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)bcopy.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: bcopy.c,v 1.13 2001/02/08 18:33:50 wiz Exp $");
+__RCSID("$NetBSD: bcopy.c,v 1.14 2002/07/04 15:48:41 kent Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -132,6 +132,8 @@
*/
src += length;
dst += length;
+ _DIAGASSERT((unsigned long)dst >= (unsigned long)dst0);
+ _DIAGASSERT((unsigned long)src >= (unsigned long)src0);
u = (unsigned long)src;
if ((u | (unsigned long)dst) & wmask) {
if ((u ^ (unsigned long)dst) & wmask || length <= wsize)
Home |
Main Index |
Thread Index |
Old Index