Skip to content

Commit

Permalink
Don't run (shell) under test/fuzzing.
Browse files Browse the repository at this point in the history
  • Loading branch information
skx committed Oct 15, 2022
1 parent 658ec64 commit 696c2ad
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package builtins

import (
"bytes"
"flag"
"fmt"
"math"
"math/rand"
Expand Down Expand Up @@ -374,7 +375,6 @@ func errorFn(env *env.Environment, args []primitive.Primitive) primitive.Primiti
return primitive.Error(args[0].ToString())
}


// existsFn returns whether the given path exists.
func existsFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {

Expand All @@ -397,7 +397,6 @@ func existsFn(env *env.Environment, args []primitive.Primitive) primitive.Primit
return primitive.Bool(false)
}


// Convert a string such as "steve\tkemp" into "steve<TAB>kemp"
func expandStr(input string) string {
out := ""
Expand Down Expand Up @@ -562,7 +561,7 @@ func globFn(env *env.Environment, args []primitive.Primitive) primitive.Primitiv

var ret primitive.List

for _, ent := range(out) {
for _, ent := range out {
ret = append(ret, primitive.String(ent))
}

Expand Down Expand Up @@ -954,8 +953,8 @@ func shellFn(env *env.Environment, args []primitive.Primitive) primitive.Primiti
}

// The argument must be a list
lst, ok := args[0].(primitive.List);
if ! ok {
lst, ok := args[0].(primitive.List)
if !ok {
return primitive.Error("argument not a list")
}

Expand All @@ -966,6 +965,12 @@ func shellFn(env *env.Environment, args []primitive.Primitive) primitive.Primiti
cArgs = append(cArgs, arg.ToString())
}

// If we're running a test-case we'll stop here, because
// fuzzing might run commands.
if flag.Lookup("test.v") != nil {
return primitive.List{}
}

cmd := exec.Command(cArgs[0], cArgs[1:]...)
var outb, errb bytes.Buffer
cmd.Stdout = &outb
Expand Down

0 comments on commit 696c2ad

Please sign in to comment.