From 4de2e81ee4e2aea8aa7a9748b74a07d39a9e8359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Milkovi=C4=8D?= Date: Sat, 2 Dec 2023 14:11:35 +0100 Subject: [PATCH] Fixed check in ranges for equal bounds (#67) This is correct in YARA but invalid in gyp. The ranges include both ends of bounds so something like `1..1` is still valid. --- parser/grammar.y | 2 +- tests/grammar_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/parser/grammar.y b/parser/grammar.y index c0ab541..9e137df 100644 --- a/parser/grammar.y +++ b/parser/grammar.y @@ -1065,7 +1065,7 @@ range { if start, ok := $2.(*ast.LiteralInteger); ok { if end, ok := $4.(*ast.LiteralInteger); ok { - if (start.Value >= end.Value) { + if (start.Value > end.Value) { lexer := asLexer(yrlex) return lexer.setError( gyperror.InvalidValueError, diff --git a/tests/grammar_test.go b/tests/grammar_test.go index 8f31d8a..eb64e5f 100644 --- a/tests/grammar_test.go +++ b/tests/grammar_test.go @@ -839,6 +839,7 @@ func TestNegativeUpperRange(t *testing.T) { assert.Equal(t, "line 6: upper bound can not be negative", err.Error()) } } + func TestInvalidRange(t *testing.T) { _, err := gyp.ParseString(` rule INVALID_RANGE { @@ -852,6 +853,17 @@ func TestInvalidRange(t *testing.T) { } } +func TestEqualBoundsRange(t *testing.T) { + _, err := gyp.ParseString(` + rule EQUAL_BOUNDS_RANGE { + strings: + $a = "AXSERS" + condition: + $a in (1..1) + }`) + assert.NoError(t, err) +} + // { ~?? } is an error func TestHexNotWildcard(t *testing.T) { _, err := gyp.ParseString(`