mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-12-05 07:01:53 -06:00
filter: Fix runtime panic on negative shift amount
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"wwfc/filter"
|
||||
@@ -19,7 +19,7 @@ func createSqlFilter(conn *pgconn.PgConn, basenode *filter.TreeNode) (value stri
|
||||
defer func() {
|
||||
if str := recover(); str != nil {
|
||||
value = ""
|
||||
err = errors.New(str.(string))
|
||||
err = fmt.Errorf("%v", str)
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
package filter
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -19,7 +19,7 @@ func Eval(basenode *TreeNode, context map[string]string, queryGame string) (valu
|
||||
defer func() {
|
||||
if str := recover(); str != nil {
|
||||
value = 0
|
||||
err = errors.New(str.(string))
|
||||
err = fmt.Errorf("%v", str)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -314,10 +314,16 @@ func (e *expression) evalMathXor(val1, val2 int64) int64 {
|
||||
}
|
||||
|
||||
func (e *expression) evalMathLShift(val1, val2 int64) int64 {
|
||||
if val2 < 0 {
|
||||
panic("negative shift amount")
|
||||
}
|
||||
return val1 << val2
|
||||
}
|
||||
|
||||
func (e *expression) evalMathRShift(val1, val2 int64) int64 {
|
||||
if val2 < 0 {
|
||||
panic("negative shift amount")
|
||||
}
|
||||
return val1 >> val2
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
package serverbrowser
|
||||
package filter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"wwfc/filter"
|
||||
)
|
||||
|
||||
func parseFilter(t *testing.T, expression string) {
|
||||
_, err := filter.Parse(expression)
|
||||
_, err := Parse(expression)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func evalFilter(t *testing.T, expression string, queryGame string, context map[string]string) {
|
||||
tree, err := filter.Parse(expression)
|
||||
tree, err := Parse(expression)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
ret, err := filter.Eval(tree, context, queryGame)
|
||||
ret, err := Eval(tree, context, queryGame)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
@@ -2,7 +2,6 @@
|
||||
package filter
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode"
|
||||
@@ -22,7 +21,7 @@ func Parse(input string) (root *TreeNode, err error) {
|
||||
defer func() {
|
||||
if str := recover(); str != nil {
|
||||
root = nil
|
||||
err = errors.New(str.(string))
|
||||
err = fmt.Errorf("%v", str)
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user