about summary refs log tree commit diff
path: root/sysdeps/x86_64/multiarch
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2022-12-01 16:36:02 -0800
committerH.J. Lu <hjl.tools@gmail.com>2022-12-02 08:18:41 -0800
commite5672763c44f16ddbc42809f5def7c6a962602bd (patch)
treea34a3791fc27a9402cb0f78c611e8d5de568c316 /sysdeps/x86_64/multiarch
parentf566b028524149ddfebe7f9770a3befb13b81a13 (diff)
downloadglibc-e5672763c44f16ddbc42809f5def7c6a962602bd.tar.gz
glibc-e5672763c44f16ddbc42809f5def7c6a962602bd.tar.xz
glibc-e5672763c44f16ddbc42809f5def7c6a962602bd.zip
x86-64 strncpy: Properly handle the length parameter [BZ# 29839]
On x32, the size_t parameter may be passed in the lower 32 bits of a
64-bit register with the non-zero upper 32 bits.  The string/memory
functions written in assembly can only use the lower 32 bits of a
64-bit register as length or must clear the upper 32 bits before using
the full 64-bit register for length.

This pach fixes strncpy for x32.  Tested on x86-64 and x32.  On x86-64,
libc.so is the same with and without the fix.
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
Diffstat (limited to 'sysdeps/x86_64/multiarch')
-rw-r--r--sysdeps/x86_64/multiarch/strncpy-avx2.S4
-rw-r--r--sysdeps/x86_64/multiarch/strncpy-evex.S4
2 files changed, 8 insertions, 0 deletions
diff --git a/sysdeps/x86_64/multiarch/strncpy-avx2.S b/sysdeps/x86_64/multiarch/strncpy-avx2.S
index e9afd8fbed..3e6350ce4a 100644
--- a/sysdeps/x86_64/multiarch/strncpy-avx2.S
+++ b/sysdeps/x86_64/multiarch/strncpy-avx2.S
@@ -52,6 +52,10 @@
 
 	.section SECTION(.text), "ax", @progbits
 ENTRY(STRNCPY)
+# ifdef __ILP32__
+	/* Clear the upper 32 bits.  */
+	movl	%edx, %edx
+# endif
 	/* Filter zero length strings and very long strings.  Zero
 	   length strings just return, very long strings are handled by
 	   just running rep stos{b|l} to zero set (which will almost
diff --git a/sysdeps/x86_64/multiarch/strncpy-evex.S b/sysdeps/x86_64/multiarch/strncpy-evex.S
index 49eaf4cbd9..dec8cccc2b 100644
--- a/sysdeps/x86_64/multiarch/strncpy-evex.S
+++ b/sysdeps/x86_64/multiarch/strncpy-evex.S
@@ -80,6 +80,10 @@
 
 	.section SECTION(.text), "ax", @progbits
 ENTRY(STRNCPY)
+# ifdef __ILP32__
+	/* Clear the upper 32 bits.  */
+	movl	%edx, %edx
+# endif
 	/* Filter zero length strings and very long strings.  Zero
 	   length strings just return, very long strings are handled by
 	   just running rep stos{b|l} to zero set (which will almost