Blob Blame History Raw
From 6adc7dbeccecff18357751b9eecfa232ee8a8172 Mon Sep 17 00:00:00 2001
From: Serhei Makarov <smakarov@redhat.com>
Date: Tue, 13 Nov 2018 11:42:46 -0500
Subject: [PATCH 29/32] PR23860 bpf_interpret() :: NEG should not fall through
 to DIV

---
 stapbpf/bpfinterp.cxx | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/stapbpf/bpfinterp.cxx b/stapbpf/bpfinterp.cxx
index 13ac8ee71..2a90c24c9 100644
--- a/stapbpf/bpfinterp.cxx
+++ b/stapbpf/bpfinterp.cxx
@@ -254,18 +254,23 @@ bpf_interpret(size_t ninsns, const struct bpf_insn insns[],
 	case BPF_ALU64 | BPF_MOV | BPF_K:  dr = s1; break;
 	case BPF_ALU64 | BPF_ARSH | BPF_X:
 	case BPF_ALU64 | BPF_ARSH | BPF_K: dr = (int64_t)dr >> s1; break;
-	case BPF_ALU64 | BPF_NEG:	   dr = -sr;
-					   /* Fallthrough */
+	case BPF_ALU64 | BPF_NEG:	   dr = -sr; break;
 	case BPF_ALU64 | BPF_DIV | BPF_X:
 	case BPF_ALU64 | BPF_DIV | BPF_K:
 	  if (s1 == 0)
-	    return 0;
+            {
+              // TODO: Signal a proper error.
+              return 0;
+            }
 	  dr /= s1;
 	  break;
 	case BPF_ALU64 | BPF_MOD | BPF_X:
 	case BPF_ALU64 | BPF_MOD | BPF_K:
 	  if (s1 == 0)
-	    return 0;
+            {
+              // TODO: Signal a proper error.
+              return 0;
+            }
 	  dr %= s1;
 	  break;
 
@@ -289,18 +294,23 @@ bpf_interpret(size_t ninsns, const struct bpf_insn insns[],
 	case BPF_ALU | BPF_MOV | BPF_K:  dr = (uint32_t)s1; break;
 	case BPF_ALU | BPF_ARSH | BPF_X:
 	case BPF_ALU | BPF_ARSH | BPF_K: dr = (int32_t)dr >> s1; break;
-	case BPF_ALU | BPF_NEG:		 dr = -(uint32_t)sr;
-					 /* Fallthrough */
+	case BPF_ALU | BPF_NEG:		 dr = -(uint32_t)sr; break;
 	case BPF_ALU | BPF_DIV | BPF_X:
 	case BPF_ALU | BPF_DIV | BPF_K:
 	  if ((uint32_t)s1 == 0)
-	    return 0;
+            {
+              // TODO: Signal a proper error.
+              return 0;
+            }
 	  dr = (uint32_t)dr / (uint32_t)s1;
 	  break;
 	case BPF_ALU | BPF_MOD | BPF_X:
 	case BPF_ALU | BPF_MOD | BPF_K:
 	  if ((uint32_t)s1 == 0)
-	    return 0;
+            {
+              // TODO: Signal a proper error.
+              return 0;
+            }
 	  dr = (uint32_t)dr % (uint32_t)s1;
 	  break;
 
-- 
2.14.5