/
run_linux.go
47 lines (38 loc) · 1.16 KB
/
run_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package francis
import (
"fmt"
"github.com/bnagy/crashwalk/crash"
"go/build"
"io/ioutil"
"os/exec"
"path/filepath"
"strconv"
"strings"
)
func (e *Engine) Run(command []string, filename string, memlimit, timeout int) (crash.Info, error) {
pkg, err := build.Import("github.com/bnagy/francis", ".", build.FindOnly)
if err != nil {
return crash.Info{}, fmt.Errorf("Couldn't find import path: %s", err)
}
tool := filepath.Join(pkg.Dir, "exploitaben/exploitaben.py")
// Construct the command array
// TODO LINUX - we don't have MallocScribble, is there an easy equivalent?
cmdSlice := []string{tool}
if e.Timeout > 0 {
cmdSlice = append(cmdSlice, []string{"-t", strconv.Itoa(e.Timeout)}...)
}
cmdSlice = append(cmdSlice, "--")
cmdSlice = append(cmdSlice, command...)
cmdStr := strings.Join(cmdSlice, " ")
cmd := exec.Command(cmdSlice[0], cmdSlice[1:]...)
stdout, err := cmd.StdoutPipe()
if err != nil {
return crash.Info{}, fmt.Errorf("Error creating pipe: %s", err)
}
if err := cmd.Start(); err != nil {
return crash.Info{}, fmt.Errorf("Error launching tool: %s", err)
}
out, _ := ioutil.ReadAll(stdout)
cmd.Wait()
return getCrashInfo(out, cmdStr)
}