-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexec.go
36 lines (31 loc) · 825 Bytes
/
exec.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
// Copyright 2018 Terence Tarvis. All rights reserved.
//
package main
import (
"go/ast"
)
func init() {
register("exec",
"this checks for use of exec Command",
execCheck,
callExpr)
}
func execCheck(f *File, node ast.Node) {
// todo: dry this out. The function name extraction needs to be moved
// as similar code appears elsewhere;
if call, ok := node.(*ast.CallExpr); ok {
if fun, ok := call.Fun.(*ast.SelectorExpr); ok {
// SelectorExpr has two fields
// X and Sel
// X (through reflection) was found to be an Ident
// Idents have a field Name also
if id, ok := (fun.X).(*ast.Ident); ok {
if(id.Name == "exec") && (fun.Sel.Name == "Command") {
callStr := f.ASTString(call);
f.Reportf(node.Pos(), "audit use of os/exec package: %s", callStr);
}
}
}
}
return;
}