Skip to content

Commit

Permalink
Fixed check in ranges for equal bounds (VirusTotal#67)
Browse files Browse the repository at this point in the history
This is correct in YARA but invalid in gyp. The ranges include both ends
of bounds so something like `1..1` is still valid.
  • Loading branch information
metthal authored Dec 2, 2023
1 parent e8eb4aa commit 4de2e81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parser/grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions tests/grammar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(`
Expand Down

0 comments on commit 4de2e81

Please sign in to comment.