Skip to content

Commit a59f468

Browse files
Fushuai WangAlexei Starovoitov
authored andcommitted
selftests/bpf: fix signedness bug in redir_partial()
When xsend() returns -1 (error), the check 'n < sizeof(buf)' incorrectly treats it as success due to unsigned promotion. Explicitly check for -1 first. Fixes: a4b7193 ("selftests/bpf: Add sockmap test for redirecting partial skb data") Signed-off-by: Fushuai Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 1c66f4a commit a59f468

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

tools/testing/selftests/bpf/prog_tests/sockmap_listen.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,8 @@ static void redir_partial(int family, int sotype, int sock_map, int parser_map)
924924
goto close;
925925

926926
n = xsend(c1, buf, sizeof(buf), 0);
927+
if (n == -1)
928+
goto close;
927929
if (n < sizeof(buf))
928930
FAIL("incomplete write");
929931

0 commit comments

Comments
 (0)