Module Name:    src
Committed By:   ryo
Date:           Mon Jul  9 06:07:06 UTC 2018

Modified Files:
        src/common/lib/libc/arch/aarch64/string: memcmp.S

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


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/common/lib/libc/arch/aarch64/string/memcmp.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/common/lib/libc/arch/aarch64/string/memcmp.S
diff -u src/common/lib/libc/arch/aarch64/string/memcmp.S:1.2 src/common/lib/libc/arch/aarch64/string/memcmp.S:1.3
--- src/common/lib/libc/arch/aarch64/string/memcmp.S:1.2	Sun Feb  4 21:52:16 2018
+++ src/common/lib/libc/arch/aarch64/string/memcmp.S	Mon Jul  9 06:07:06 2018
@@ -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 @@ ENTRY(memcmp)
 	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 */

Reply via email to