Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/common/lib/libc/arch/aarch64/string avoid reading from out o...



details:   https://anonhg.NetBSD.org/src/rev/ae93552c886d
branches:  trunk
changeset: 323929:ae93552c886d
user:      ryo <ryo%NetBSD.org@localhost>
date:      Mon Jul 09 06:07:06 2018 +0000

description:
avoid reading from out of range that may cause access fault.

diffstat:

 common/lib/libc/arch/aarch64/string/memcmp.S |  14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diffs (42 lines):

diff -r 35c85182c24a -r ae93552c886d common/lib/libc/arch/aarch64/string/memcmp.S
--- a/common/lib/libc/arch/aarch64/string/memcmp.S      Mon Jul 09 05:43:35 2018 +0000
+++ b/common/lib/libc/arch/aarch64/string/memcmp.S      Mon Jul 09 06:07:06 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: memcmp.S,v 1.2 2018/02/04 21:52:16 skrll Exp $ */
+/* $NetBSD: memcmp.S,v 1.3 2018/07/09 06:07:06 ryo Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <machine/asm.h>
 
-RCSID("$NetBSD: memcmp.S,v 1.2 2018/02/04 21:52:16 skrll Exp $")
+RCSID("$NetBSD: memcmp.S,v 1.3 2018/07/09 06:07:06 ryo Exp $")
 
 ENTRY(memcmp)
        mov     x9, x0
@@ -55,17 +55,19 @@
        sub     x2, x2, #8              /* now subtract a dword */
 
        sub     x9, x9, x3              /* dword align src1 */
-       sub     x10, x10, x3            /* adjust src2 */
 
+       ldr     x6, [x10], #8           /* load dword from src2 */
+       sub     x10, x10, x3            /* src2 -= x3 */
        lsl     x3, x3, #3              /* convert bytes to bits */
        ldr     x4, [x9], #8            /* load dword from src1 */
-       ldr     x6, [x10], #8           /* load dword from src2 */
 #ifdef __AARCH64EB__
        lsl     x4, x4, x3              /* discard leading bytes from data1 */
-       lsl     x6, x6, x3              /* discard leading bytes from data2 */
+       lsr     x6, x6, x3              /* discard leading bytes from data2 */
+       lsl     x6, x6, x3              /* get back bit position */
 #else
        lsr     x4, x4, x3              /* discard leading bytes from data1 */
-       lsr     x6, x6, x3              /* discard leading bytes from data2 */
+       lsl     x6, x6, x3              /* discard leading bytes from data2 */
+       lsr     x6, x6, x3              /* get back bit position */
 #endif
        subs    x0, x4, x6              /* compare data */
        b.ne    .Lmemcmp_last_compare   /* difference.  find it */



Home | Main Index | Thread Index | Old Index