Fix null pointer issue found by fuzz test

This commit is contained in:
Vikram Rangnekar 2019-04-20 17:27:03 -04:00
parent c03f7d6576
commit 74ea365c5a
3 changed files with 19 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package qcode package qcode
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
"unicode" "unicode"
@ -207,6 +208,9 @@ func (l *lexer) errorf(format string, args ...interface{}) stateFn {
// lex creates a new scanner for the input string. // lex creates a new scanner for the input string.
func lex(input string) (*lexer, error) { func lex(input string) (*lexer, error) {
if len(input) == 0 {
return nil, errors.New("empty query")
}
l := &lexer{ l := &lexer{
input: input, input: input,
items: make([]item, 0, 100), items: make([]item, 0, 100),

View File

@ -57,3 +57,11 @@ func TestCompile(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
} }
func TestEmptyCompile(t *testing.T) {
qcompile, _ := NewCompiler(Config{})
_, err := qcompile.CompileQuery(``)
if err == nil {
t.Fatal(errors.New("expecting an error"))
}
}

View File

@ -336,7 +336,13 @@ func (com *Compiler) compileQuery(op *Operation) (*Query, error) {
} }
} }
fil, ok := com.fm[selRoot.Table] var ok bool
var fil *Exp
if selRoot != nil {
fil, ok = com.fm[selRoot.Table]
}
if !ok || fil == nil { if !ok || fil == nil {
fil = com.fl fil = com.fl
} }