• Tony Ambardar's avatar
    selftests/bpf: Fix arg parsing in veristat, test_progs · 03bfcda1
    Tony Ambardar authored
    Current code parses arguments with strtok_r() using a construct like
    
        char *state = NULL;
        while ((next = strtok_r(state ? NULL : input, ",", &state))) {
            ...
        }
    
    where logic assumes the 'state' var can distinguish between first and
    subsequent strtok_r() calls, and adjusts parameters accordingly. However,
    'state' is strictly internal context for strtok_r() and no such assumptions
    are supported in the man page. Moreover, the exact behaviour of 'state'
    depends on the libc implementation, making the above code fragile.
    
    Indeed, invoking "./test_progs -t <test_name>" on mips64el/musl will hang,
    with the above code in an infinite loop.
    
    Similarly, we see strange behaviour running 'veristat' on mips64el/musl:
    
        $ ./veristat -e file,prog,verdict,insns -C two-ok add-failure
        Can't specify more than 9 stats
    
    Rewrite code using a counter to distinguish between strtok_r() calls.
    
    Fixes: 61ddff37 ("selftests/bpf: Improve by-name subtest selection logic in prog_tests")
    Fixes: 394169b0 ("selftests/bpf: add comparison mode to veristat")
    Fixes: c8bc5e05 ("selftests/bpf: Add veristat tool for mass-verifying BPF object files")
    Signed-off-by: default avatarTony Ambardar <tony.ambardar@gmail.com>
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/392d8bf5559f85fa37926c1494e62312ef252c3d.1722244708.git.tony.ambardar@gmail.com
    03bfcda1
testing_helpers.c 10 KB