Michal,
thanks for fixing this.
I might want to add into the commit message that this was introduced
with commit:
40cbaa8fbe rpcgen: add test case for XDR serialization
Reviewed-by: Boris Fiuczynski <fiuczy(a)linux.ibm.com>
and tested as well.
On 11/29/23 13:00, Michal Privoznik wrote:
There are some platforms where 'char' is unsigned, by
default
(RPi, s390x to name a few). And because of how test_demo is
written we are experiencing some test cases failing there. For
instance: /xdr/struct-scalar is failing. This is because in the
test (test_struct_scalar()), we have a struct with two chars. One
is initialized to 0xca, the other 0xfe (note that both have the
MSB set). The XDR encoder (xdr_TestStructScalar()) then calls
xdr_char() on both of them. But XDR itself has no notion of
char type, so under the hood, it expands it to int [1] and calls
xdr_int(). And this is where the problem lies. On platforms where
char is signed, the integer expansion results in 0xffffffca, but
on platforms where char is unsigned it results in 0x000000ca. Two
distinct results.
The test then goes and compares the encoded buffer with an
expected one (memcmp(), read from the disk earlier).
This poses no problem for real life use, because when decoding
those chars back, the padding is thrown away.
To avoid tickling this issue, use values that don't have the MSB
set.
1:https://git.linux-nfs.org/?p=steved/libtirpc.git;a=blob;f=src/xdr.c;h=2...
Reported-by: Boris Fiuczynski<fiuczy(a)linux.ibm.com>
Signed-off-by: Michal Privoznik<mprivozn(a)redhat.com>
---
scripts/rpcgen/tests/test_demo.c | 2 +-
.../tests/test_demo_struct_fixed_array.bin | Bin 136 -> 136 bytes
.../tests/test_demo_struct_pointer_set.bin | Bin 12 -> 12 bytes
.../rpcgen/tests/test_demo_struct_scalar.bin | Bin 8 -> 8 bytes
.../test_demo_struct_variable_array_set.bin | Bin 28 -> 28 bytes
.../tests/test_demo_test_struct_all_types.bin | Bin 1752 -> 1752 bytes
6 files changed, 1 insertion(+), 1 deletion(-)
--
Mit freundlichen Grüßen/Kind regards
Boris Fiuczynski
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Gregor Pillen
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294