.POWER9-optimized strncpy function no longer gives incorrect results
Previously, the POWER9 strncpy function did not use the correct register as the source of the NUL bytes for padding. Consequently, the output buffer contained uninitialized register content instead of the NUL padding. With this update, the strncpy function has been fixed, and the end of the output buffer is now correctly padded with NUL bytes.
Zdenek Sojka reported that strncpy does not always clear the destination buffer. The upstream bug gives the following reproducer:
#include <string.h>
#include <stdlib.h>
#define N 3
char a[N];
char c[N];
int
main (void)
{
__asm__ volatile ("xxspltib 18, 0xf":::"vs18");
strncpy (c, a, N);
for (unsigned i = 0; i < N; i++)
if (c[i])
abort ();
return 0;
}
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.
For information on the advisory (glibc bug fix and enhancement update), and where to find the updated
files, follow the link below.
If the solution does not work for you, open a new bug report.
https://access.redhat.com/errata/RHBA-2022:8272
Zdenek Sojka reported that strncpy does not always clear the destination buffer. The upstream bug gives the following reproducer: #include <string.h> #include <stdlib.h> #define N 3 char a[N]; char c[N]; int main (void) { __asm__ volatile ("xxspltib 18, 0xf":::"vs18"); strncpy (c, a, N); for (unsigned i = 0; i < N; i++) if (c[i]) abort (); return 0; }