lang: ast, core: Add some safety checks
I don't think I'm hitting these, but good for debugging.
This commit is contained in:
@@ -868,9 +868,18 @@ func (obj *StmtRes) Output(table map[interfaces.Func]types.Value) (*interfaces.O
|
|||||||
}
|
}
|
||||||
|
|
||||||
s := name.Str() // must not panic
|
s := name.Str() // must not panic
|
||||||
|
if s == "" {
|
||||||
|
return nil, fmt.Errorf("empty name")
|
||||||
|
}
|
||||||
names = append(names, s)
|
names = append(names, s)
|
||||||
// host is the input telling us who we want to pull from
|
// host is the input telling us who we want to pull from
|
||||||
hosts[s] = host.Str() // correspondence map
|
hosts[s] = host.Str() // correspondence map
|
||||||
|
if hosts[s] == "" {
|
||||||
|
return nil, fmt.Errorf("empty host")
|
||||||
|
}
|
||||||
|
if hosts[s] == "*" { // safety
|
||||||
|
return nil, fmt.Errorf("invalid star host")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for n, m := range mapping { // delete everything else
|
for n, m := range mapping { // delete everything else
|
||||||
if !util.StrInList(n, names) {
|
if !util.StrInList(n, names) {
|
||||||
@@ -999,6 +1008,19 @@ func (obj *StmtRes) collect(table map[interfaces.Func]types.Value) (map[string]m
|
|||||||
n := name.Str() // must not panic
|
n := name.Str() // must not panic
|
||||||
h := host.Str() // must not panic
|
h := host.Str() // must not panic
|
||||||
|
|
||||||
|
if n == "" {
|
||||||
|
// programming error
|
||||||
|
return nil, fmt.Errorf("name field is empty")
|
||||||
|
}
|
||||||
|
if h == "" {
|
||||||
|
// programming error
|
||||||
|
return nil, fmt.Errorf("host field is empty")
|
||||||
|
}
|
||||||
|
if h == "*" {
|
||||||
|
// programming error
|
||||||
|
return nil, fmt.Errorf("host field is a start")
|
||||||
|
}
|
||||||
|
|
||||||
if _, exists := m[n]; !exists {
|
if _, exists := m[n]; !exists {
|
||||||
m[n] = make(map[string]string)
|
m[n] = make(map[string]string)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -482,6 +482,9 @@ func (obj *CollectFunc) Call(ctx context.Context, args []types.Value) (types.Val
|
|||||||
if x.Host == "" {
|
if x.Host == "" {
|
||||||
return nil, fmt.Errorf("unexpected empty host")
|
return nil, fmt.Errorf("unexpected empty host")
|
||||||
}
|
}
|
||||||
|
if x.Host == "*" { // safety check
|
||||||
|
return nil, fmt.Errorf("unexpected star host")
|
||||||
|
}
|
||||||
if x.Data == "" {
|
if x.Data == "" {
|
||||||
return nil, fmt.Errorf("unexpected empty data")
|
return nil, fmt.Errorf("unexpected empty data")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user