glibc/sysdeps
Noah Goldstein 49953727d1 x86: Fix bug in strchrnul-evex512 [BZ #32078]
Issue was we were expecting not matches with CHAR before the start of
the string in the page cross case.

The check code in the page cross case:
```
    and    $0xffffffffffffffc0,%rax
    vmovdqa64 (%rax),%zmm17
    vpcmpneqb %zmm17,%zmm16,%k1
    vptestmb %zmm17,%zmm17,%k0{%k1}
    kmovq  %k0,%rax
    inc    %rax
    shr    %cl,%rax
    je     L(continue)
```

expects that all characters that neither match null nor CHAR will be
1s in `rax` prior to the `inc`. Then the `inc` will overflow all of
the 1s where no relevant match was found.

This is incorrect in the page-cross case, as the
`vmovdqa64 (%rax),%zmm17` loads from before the start of the input
string.

If there are matches with CHAR before the start of the string, `rax`
won't properly overflow.

The fix is quite simple. Just replace:

```
    inc    %rax
    shr    %cl,%rax
```
With:
```
    sar    %cl,%rax
    inc    %rax
```

The arithmetic shift will clear any matches prior to the start of the
string while maintaining the signbit so the 1s can properly overflow
to zero in the case of no matches.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

(cherry picked from commit 7da0886247)
2024-08-15 13:26:05 -07:00
..
aarch64
alpha
arc
arm
csky
generic Add mremap tests 2024-08-01 14:21:57 +02:00
gnu
hppa
htl
hurd
i386 math: Fix i386 and m68k exp10 on static build (BZ 31775) 2024-07-02 14:25:56 +02:00
ieee754 math: Provide missing math symbols on libc.a (BZ 31781) 2024-07-02 14:37:44 +02:00
loongarch
m68k math: Fix i386 and m68k exp10 on static build (BZ 31775) 2024-07-02 14:25:56 +02:00
mach
microblaze
mips
nios2
nptl Linux: Make __rseq_size useful for feature detection (bug 31965) 2024-07-16 16:35:29 +02:00
or1k
posix
powerpc
pthread
riscv
s390 s390x: Fix segfault in wcsncmp [BZ #31934] 2024-07-16 10:25:35 +02:00
sh
sparc
unix x32/cet: Support shadow stack during startup for Linux 6.10 2024-08-12 10:54:17 -07:00
wordsize-32
wordsize-64
x86 x86: Properly set x86 minimum ISA level [BZ #31883] 2024-06-15 11:13:10 +01:00
x86_64 x86: Fix bug in strchrnul-evex512 [BZ #32078] 2024-08-15 13:26:05 -07:00