]> www.infradead.org Git - nvme.git/commitdiff
selftests/bpf: Check length of recv in test_sockmap
authorGeliang Tang <tanggeliang@kylinos.cn>
Thu, 23 May 2024 06:50:03 +0000 (14:50 +0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 3 Jun 2024 17:32:55 +0000 (19:32 +0200)
The value of recv in msg_loop may be negative, like EWOULDBLOCK, so it's
necessary to check if it is positive before accumulating it to bytes_recvd.

Fixes: 16962b2404ac ("bpf: sockmap, add selftests")
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Jakub Sitnicki <jakub@cloudflare.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/5172563f7c7b2a2e953cef02e89fc34664a7b190.1716446893.git.tanggeliang@kylinos.cn
tools/testing/selftests/bpf/test_sockmap.c

index e29f8203bd4f1c2b521371371e6a704af113ed42..9cba4ec844a53712eb7cb007379faabe139521cb 100644 (file)
@@ -681,7 +681,8 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
                                }
                        }
 
-                       s->bytes_recvd += recv;
+                       if (recv > 0)
+                               s->bytes_recvd += recv;
 
                        if (opt->check_recved_len && s->bytes_recvd > total_bytes) {
                                errno = EMSGSIZE;