From 984042af303ce8ecccc8d896333e9c88738f13f8 Mon Sep 17 00:00:00 2001 From: Serhei Makarov Date: Mon, 15 Jul 2019 12:53:29 -0400 Subject: [PATCH] stapbpf PR24811 test :: unveil a nasty lurking segfault case in foreach loops --- .../bpf_tests/foreach_pr24811.stp | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 testsuite/systemtap.bpf/bpf_tests/foreach_pr24811.stp diff --git a/testsuite/systemtap.bpf/bpf_tests/foreach_pr24811.stp b/testsuite/systemtap.bpf/bpf_tests/foreach_pr24811.stp new file mode 100644 index 000000000..b013fe83d --- /dev/null +++ b/testsuite/systemtap.bpf/bpf_tests/foreach_pr24811.stp @@ -0,0 +1,42 @@ +global a[10], b[10] + +// used so the foreach limit expression is NOT a constant, else it's optimized +global lim = 1 + +probe begin { + printf("BEGIN\n") + + a[2] = -2 + a[1] = -1 + a[0] = 0 + a[-1] = 1 + a[-2] = 2 + + b[1] = 1 + b[0] = 0 + b[-1] = -1 + + lim = 0 + exit() +} + +probe end { + flag = 1 + + foreach (k1- in a) { // push sorted data for a + printf("got %d, should be negative %d\n", k1, a[k1]) + flag = flag && k1 == (0-a[k1]) // check data for a + foreach (k2- in b) { // push sorted data for b + printf("got %d, should be exactly %d\n", k2, b[k2]) + flag = flag && k2 == b[k2] // check data for b + foreach (k3- in a limit lim) { // bug -- don't push, pop sorted data for b + flag = 0 // should not be invoked + } // bug -- after popping, will read sorted data for a on next iteration + } // pop sorted data for b, but with bug pops a + } // pop sorted data for a, but with bug pops -- segfault? + + if (flag) + printf("END PASS\n") + else + printf("END FAIL\n") +} -- 2.43.5