]> sourceware.org Git - glibc.git/commitdiff
x86-64 strncpy: Properly handle the length parameter [BZ# 29839]
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 2 Dec 2022 00:36:02 +0000 (16:36 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 2 Dec 2022 16:18:41 +0000 (08:18 -0800)
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>
sysdeps/x86_64/multiarch/strncpy-avx2.S
sysdeps/x86_64/multiarch/strncpy-evex.S

index e9afd8fbed120eec1a6918e810ca20e81dbbe344..3e6350ce4aa73dec9b1404e6e71f685cada7323c 100644 (file)
 
        .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
index 49eaf4cbd9610a16ffbc4e6e5c9d6bacd1caf421..dec8cccc2bea07da473b0ff747ea07c029691bd9 100644 (file)
 
        .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
This page took 0.046131 seconds and 5 git commands to generate.