From 3703f1d2e6e5a48c5fe066a7df0d1cc7f76ea4f0 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 22 Sep 2017 16:00:29 -0400 Subject: [PATCH] Filter: catch shift undefined behavior Signed-off-by: Mathieu Desnoyers --- liblttng-ust/lttng-filter-interpreter.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/liblttng-ust/lttng-filter-interpreter.c b/liblttng-ust/lttng-filter-interpreter.c index 1e7b12a5..1354d9c1 100644 --- a/liblttng-ust/lttng-filter-interpreter.c +++ b/liblttng-ust/lttng-filter-interpreter.c @@ -1557,7 +1557,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, ret = -EINVAL; goto end; } - + /* Catch undefined behavior. */ + if (caa_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, ax_t, bx_t); estack_ax_v = res; @@ -1574,7 +1578,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, ret = -EINVAL; goto end; } - + /* Catch undefined behavior. */ + if (caa_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, ax_t, bx_t); estack_ax_v = res; -- 2.34.1