From ea13ec960f55bac1d08e5ec3523797ccdbde573b Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 22 Sep 2017 16:00:13 -0400 Subject: [PATCH] Filter: catch shift undefined behavior Signed-off-by: Mathieu Desnoyers --- lttng-filter-interpreter.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lttng-filter-interpreter.c b/lttng-filter-interpreter.c index 5bf0bd60..b1e5ba73 100644 --- a/lttng-filter-interpreter.c +++ b/lttng-filter-interpreter.c @@ -990,6 +990,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { int64_t res; + /* Catch undefined behavior. */ + if (unlikely(estack_ax_v < 0 || estack_ax_v >= 64)) { + ret = -EINVAL; + goto end; + } res = (estack_bx_v >> estack_ax_v); estack_pop(stack, top, ax, bx); estack_ax_v = res; @@ -1000,6 +1005,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { int64_t res; + /* Catch undefined behavior. */ + if (unlikely(estack_ax_v < 0 || estack_ax_v >= 64)) { + ret = -EINVAL; + goto end; + } res = (estack_bx_v << estack_ax_v); estack_pop(stack, top, ax, bx); estack_ax_v = res; -- 2.34.1