selftests/bpf: Fix endianness issue in test_sockopt_sk
authorIlya Leoshkevich <iii@linux.ibm.com>
Tue, 15 Sep 2020 11:39:28 +0000 (13:39 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 18 Sep 2020 23:01:18 +0000 (01:01 +0200)
getsetsockopt() calls getsockopt() with optlen == 1, but then checks
the resulting int. It is ok on little endian, but not on big endian.

Fix by checking char instead.

Fixes: 8a027dc0d8f5 ("selftests/bpf: add sockopt test that exercises sk helpers")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200915113928.3768496-1-iii@linux.ibm.com
tools/testing/selftests/bpf/prog_tests/sockopt_sk.c

index 5f54c6a..b25c9c4 100644 (file)
@@ -45,9 +45,9 @@ static int getsetsockopt(void)
                goto err;
        }
 
-       if (*(int *)big_buf != 0x08) {
+       if (*big_buf != 0x08) {
                log_err("Unexpected getsockopt(IP_TOS) optval 0x%x != 0x08",
-                       *(int *)big_buf);
+                       (int)*big_buf);
                goto err;
        }