From: Mathieu Desnoyers Date: Sat, 8 Nov 2014 17:16:41 +0000 (-0500) Subject: Fix: off-by-one in sequence filter comparator X-Git-Tag: v2.6.0-rc3~8 X-Git-Url: http://git.liburcu.org/?p=lttng-ust.git;a=commitdiff_plain;h=35c7fa927fef4a851f5a22b78b7fe883789f2a5d Fix: off-by-one in sequence filter comparator If we pass the following sequence as event input: - field name "seqfield2" - seq. len.: 4 - sequence array: "testA" (5 characters), The following filters do not have the intended effect: * 'seqfield2=="testA"' - expected: no match. - actual behavior: match. * 'seqfield2=="test"' - expected: match. - actual behavior: no match. This is caused by an off-by-one in the comparison with sequence length in the filter bytecode interpreter. Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust/lttng-filter-interpreter.c b/liblttng-ust/lttng-filter-interpreter.c index 29bcaeff..df4add22 100644 --- a/liblttng-ust/lttng-filter-interpreter.c +++ b/liblttng-ust/lttng-filter-interpreter.c @@ -58,8 +58,8 @@ int stack_strcmp(struct estack *stack, int top, const char *cmp_type) for (;;) { int escaped_r0 = 0; - if (unlikely(p - estack_bx(stack, top)->u.s.str > estack_bx(stack, top)->u.s.seq_len || *p == '\0')) { - if (q - estack_ax(stack, top)->u.s.str > estack_ax(stack, top)->u.s.seq_len || *q == '\0') { + if (unlikely(p - estack_bx(stack, top)->u.s.str >= estack_bx(stack, top)->u.s.seq_len || *p == '\0')) { + if (q - estack_ax(stack, top)->u.s.str >= estack_ax(stack, top)->u.s.seq_len || *q == '\0') { return 0; } else { if (estack_ax(stack, top)->u.s.literal) { @@ -70,8 +70,8 @@ int stack_strcmp(struct estack *stack, int top, const char *cmp_type) return -1; } } - if (unlikely(q - estack_ax(stack, top)->u.s.str > estack_ax(stack, top)->u.s.seq_len || *q == '\0')) { - if (p - estack_bx(stack, top)->u.s.str > estack_bx(stack, top)->u.s.seq_len || *p == '\0') { + if (unlikely(q - estack_ax(stack, top)->u.s.str >= estack_ax(stack, top)->u.s.seq_len || *q == '\0')) { + if (p - estack_bx(stack, top)->u.s.str >= estack_bx(stack, top)->u.s.seq_len || *p == '\0') { return 0; } else { if (estack_bx(stack, top)->u.s.literal) {