diff options
author | Rasmus Villemoes <linux@rasmusvillemoes.dk> | 2022-10-21 09:01:53 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-11-10 20:14:26 +0300 |
commit | 533bfacbacb86f1e415d09e7a602de871a16a90e (patch) | |
tree | dee9a3fa13793ea7c14cf29c16e2675888a8b90e /.gitignore | |
parent | f100a02748613c108481b1d3baaa15b60494e4cc (diff) | |
download | linux-533bfacbacb86f1e415d09e7a602de871a16a90e.tar.xz |
tools/nolibc/string: Fix memcmp() implementation
commit b3f4f51ea68a495f8a5956064c33dce711a2df91 upstream.
The C standard says that memcmp() must treat the buffers as consisting
of "unsigned chars". If char happens to be unsigned, the casts are ok,
but then obviously the c1 variable can never contain a negative
value. And when char is signed, the casts are wrong, and there's still
a problem with using an 8-bit quantity to hold the difference, because
that can range from -255 to +255.
For example, assuming char is signed, comparing two 1-byte buffers,
one containing 0x00 and another 0x80, the current implementation would
return -128 for both memcmp(a, b, 1) and memcmp(b, a, 1), whereas one
of those should of course return something positive.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Fixes: 66b6f755ad45 ("rcutorture: Import a copy of nolibc")
Cc: stable@vger.kernel.org # v5.0+
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to '.gitignore')
0 files changed, 0 insertions, 0 deletions