]> sourceware.org Git - systemtap.git/commitdiff
stapbpf PR24811 test :: unveil a nasty lurking segfault case in foreach loops
authorSerhei Makarov <smakarov@redhat.com>
Mon, 15 Jul 2019 16:53:29 +0000 (12:53 -0400)
committerSerhei Makarov <smakarov@redhat.com>
Mon, 15 Jul 2019 16:53:29 +0000 (12:53 -0400)
testsuite/systemtap.bpf/bpf_tests/foreach_pr24811.stp [new file with mode: 0644]

diff --git a/testsuite/systemtap.bpf/bpf_tests/foreach_pr24811.stp b/testsuite/systemtap.bpf/bpf_tests/foreach_pr24811.stp
new file mode 100644 (file)
index 0000000..b013fe8
--- /dev/null
@@ -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 <nada> -- segfault?
+
+  if (flag)
+    printf("END PASS\n")
+  else
+    printf("END FAIL\n")
+}
This page took 0.030912 seconds and 5 git commands to generate.