selftests/bpf: fix the incorrect verification of port numbers.
authorKui-Feng Lee <thinker.li@gmail.com>
Fri, 4 Aug 2023 16:58:31 +0000 (09:58 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Fri, 4 Aug 2023 17:20:33 +0000 (10:20 -0700)
commit9eab71bd887ae28882c29a82cb0cdb00e1654c54
treef99edba628ec3e31f81dee7fea847f4963ee6bc9
parent21ce6abe178a15a0354eaaf86bea07e302075a20
selftests/bpf: fix the incorrect verification of port numbers.

Check port numbers before calling htons().

According to Dan Carpenter's report, Smatch identified incorrect port
number checks. It is expected that the returned port number is an integer,
with negative numbers indicating errors. However, the value was mistakenly
verified after being translated by htons().

Major changes from v1:

 - Move the variable 'port' to the same line of 'err'.

Fixes: 539c7e67aa4a ("selftests/bpf: Verify that the cgroup_skb filters receive expected packets.")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/bpf/cafd6585-d5a2-4096-b94f-7556f5aa7737@moroto.mountain/
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
Link: https://lore.kernel.org/r/20230804165831.173627-1-thinker.li@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
tools/testing/selftests/bpf/prog_tests/cgroup_tcp_skb.c