about summary refs log tree commit diff
path: root/sysdeps/x86_64/multiarch
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2022-09-20 17:58:04 -0700
committerSunil K Pandey <skpgkp2@gmail.com>2022-11-24 10:40:09 -0800
commitfa196d06d392f9bb2eae2f41613c6b0710f26293 (patch)
treea3ecf32ccf17270bd5456f82b6d8a195e7d586f2 /sysdeps/x86_64/multiarch
parent2ba9801d9f222de9fe1f5f04dcd1c276e56b4245 (diff)
downloadglibc-fa196d06d392f9bb2eae2f41613c6b0710f26293.tar.gz
glibc-fa196d06d392f9bb2eae2f41613c6b0710f26293.tar.xz
glibc-fa196d06d392f9bb2eae2f41613c6b0710f26293.zip
x86: Fix wcsnlen-avx2 page cross length comparison [BZ #29591]
Previous implementation was adjusting length (rsi) to match
bytes (eax), but since there is no bound to length this can cause
overflow.

Fix is to just convert the byte-count (eax) to length by dividing by
sizeof (wchar_t) before the comparison.

Full check passes on x86-64 and build succeeds w/ and w/o multiarch.

(cherry picked from commit b0969fa53a28b4ab2159806bf6c99a98999502ee)
Diffstat (limited to 'sysdeps/x86_64/multiarch')
-rw-r--r--sysdeps/x86_64/multiarch/strlen-avx2.S7
1 files changed, 2 insertions, 5 deletions
diff --git a/sysdeps/x86_64/multiarch/strlen-avx2.S b/sysdeps/x86_64/multiarch/strlen-avx2.S
index 0593fb303b..b9b58ef599 100644
--- a/sysdeps/x86_64/multiarch/strlen-avx2.S
+++ b/sysdeps/x86_64/multiarch/strlen-avx2.S
@@ -544,14 +544,11 @@ L(return_vzeroupper):
 L(cross_page_less_vec):
 	tzcntl	%eax, %eax
 #  ifdef USE_AS_WCSLEN
-	/* NB: Multiply length by 4 to get byte count.  */
-	sall	$2, %esi
+	/* NB: Divide by 4 to convert from byte-count to length.  */
+	shrl	$2, %eax
 #  endif
 	cmpq	%rax, %rsi
 	cmovb	%esi, %eax
-#  ifdef USE_AS_WCSLEN
-	shrl	$2, %eax
-#  endif
 	VZEROUPPER_RETURN
 # endif