]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: correctly move 'log' upon successful match
authorEduard Zingerman <eddyz87@gmail.com>
Tue, 20 Aug 2024 10:23:50 +0000 (03:23 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 21 Aug 2024 18:03:00 +0000 (11:03 -0700)
Suppose log="foo bar buz" and msg->substr="bar".
In such case current match processing logic would update 'log' as
follows: log += strlen(msg->substr); -> log += 3 -> log=" bar".
However, the intent behind the 'log' update is to make it point after
the successful match, e.g. to make log=" buz" in the example above.

Fixes: 4ef5d6af4935 ("selftests/bpf: no need to track next_match_pos in struct test_loader")
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20240820102357.3372779-3-eddyz87@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/test_loader.c

index 1b1290e090e74f75343d98ee4bf2daa37fc662ce..f5f5d16ac5505d739e0e2c9661d503e0c899520e 100644 (file)
@@ -522,7 +522,7 @@ static void validate_msgs(char *log_buf, struct expected_msgs *msgs,
                if (msg->substr) {
                        match = strstr(log, msg->substr);
                        if (match)
-                               log += strlen(msg->substr);
+                               log = match + strlen(msg->substr);
                } else {
                        err = regexec(&msg->regex, log, 1, reg_match, 0);
                        if (err == 0) {