Fix: use BUG_ON instead of accessing array subscript above array bounds
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 4 Apr 2016 18:39:16 +0000 (14:39 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 4 Apr 2016 18:47:46 +0000 (14:47 -0400)
commit5f12cb8d9ffdc55f04335bd08e90e5e7b10664f4
tree623a96b0ddd3fc4dbf693bda983b594f0040473d
parentc94ac1ac8ad4a732df9bc7adaa18114b3024d5aa
Fix: use BUG_ON instead of accessing array subscript above array bounds

Building lttng-modules lttng-filter-interpreter.c on a 4.6-rc kernel
triggers the following gcc warning:

In file included from /home/compudj/git/lttng-modules/lttng-filter-interpreter.c:25:0:
/home/compudj/git/lttng-modules/lttng-filter-interpreter.c: In function ‘lttng_filter_interpret_bytecode’:
/home/compudj/git/lttng-modules/lttng-filter.h:144:14: warning: array subscript is above array bounds [-Warray-bounds]
   &(stack)->e[top];    \
              ^
/home/compudj/git/lttng-modules/lttng-filter-interpreter.c:714:4: note: in expansion of macro ‘estack_ax’
    estack_ax(stack, top)->u.s.str = insn->data;
    ^
/home/compudj/git/lttng-modules/lttng-filter.h:144:14: warning: array subscript is above array bounds [-Warray-bounds]
   &(stack)->e[top];    \
              ^
/home/compudj/git/lttng-modules/lttng-filter-interpreter.c:715:4: note: in expansion of macro ‘estack_ax’
    estack_ax(stack, top)->u.s.seq_len = UINT_MAX;

This is because the bound checking is performed in a prior validation
phase (which the compiler does not know about), and we only
WARN_ON_ONCE() if the interpreter sees values that don't fit in array
range.

Use BUG_ON() in the interpreter instead, which ensures we never, ever
reach the out-of-bound condition from a compiler perspective.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lttng-filter.h
This page took 0.025185 seconds and 4 git commands to generate.