@@ -22,6 +22,20 @@ func resolveSystemArgs(argsNode *CandidateNode) []string {
2222 return nil
2323}
2424
25+ func resolveCommandNode (commandNodes Context ) (string , error ) {
26+ if commandNodes .MatchingNodes .Front () == nil {
27+ return "" , fmt .Errorf ("system operator: command expression returned no results" )
28+ }
29+ if commandNodes .MatchingNodes .Len () > 1 {
30+ log .Debugf ("system operator: command expression returned %d results, using first" , commandNodes .MatchingNodes .Len ())
31+ }
32+ cmdNode := commandNodes .MatchingNodes .Front ().Value .(* CandidateNode )
33+ if cmdNode .Kind != ScalarNode || cmdNode .Tag == "!!null" {
34+ return "" , fmt .Errorf ("system operator: command must be a string scalar" )
35+ }
36+ return cmdNode .Value , nil
37+ }
38+
2539func systemOperator (d * dataTreeNavigator , context Context , expressionNode * ExpressionNode ) (Context , error ) {
2640 if ! ConfiguredSecurityPreferences .EnableSystemOps {
2741 log .Warning ("system operator is disabled, use --enable-system-operator flag to enable" )
@@ -51,10 +65,10 @@ func systemOperator(d *dataTreeNavigator, context Context, expressionNode *Expre
5165 if err != nil {
5266 return Context {}, err
5367 }
54- if commandNodes .MatchingNodes .Front () == nil {
55- return Context {}, fmt .Errorf ("system operator: command expression returned no results" )
68+ command , err = resolveCommandNode (commandNodes )
69+ if err != nil {
70+ return Context {}, err
5671 }
57- command = commandNodes .MatchingNodes .Front ().Value .(* CandidateNode ).Value
5872
5973 argsNodes , err := d .GetMatchingNodes (nodeContext , block .RHS )
6074 if err != nil {
@@ -68,10 +82,10 @@ func systemOperator(d *dataTreeNavigator, context Context, expressionNode *Expre
6882 if err != nil {
6983 return Context {}, err
7084 }
71- if commandNodes .MatchingNodes .Front () == nil {
72- return Context {}, fmt .Errorf ("system operator: command expression returned no results" )
85+ command , err = resolveCommandNode (commandNodes )
86+ if err != nil {
87+ return Context {}, err
7388 }
74- command = commandNodes .MatchingNodes .Front ().Value .(* CandidateNode ).Value
7589 }
7690
7791 var stdin bytes.Buffer
0 commit comments