aboutsummaryrefslogtreecommitdiffstats
path: root/csource/csource.go
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@google.com>2017-05-18 17:03:02 +0200
committerAndrey Konovalov <andreyknvl@google.com>2017-06-12 19:48:23 +0200
commit73a895df6168bc12559d1fa16aae7e52646d7ec3 (patch)
tree3a1dc5c7395bbac98dc3f7f82360097f9e72011f /csource/csource.go
parent1bdb387c18a852e75aef0b3c4ddb0481f90d66bd (diff)
csource: use sandbox only when required
Diffstat (limited to 'csource/csource.go')
-rw-r--r--csource/csource.go41
1 files changed, 32 insertions, 9 deletions
diff --git a/csource/csource.go b/csource/csource.go
index 8faae8e5e..603cb37f5 100644
--- a/csource/csource.go
+++ b/csource/csource.go
@@ -86,9 +86,16 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) {
if opts.UseTmpDir {
fmt.Fprintf(w, "\tuse_temporary_dir();\n")
}
- fmt.Fprintf(w, "\tint pid = do_sandbox_%v(0, %v);\n", opts.Sandbox, opts.EnableTun)
- fmt.Fprint(w, "\tint status = 0;\n")
- fmt.Fprint(w, "\twhile (waitpid(pid, &status, __WALL) != pid) {}\n")
+ if opts.Sandbox != "" {
+ fmt.Fprintf(w, "\tint pid = do_sandbox_%v(0, %v);\n", opts.Sandbox, opts.EnableTun)
+ fmt.Fprint(w, "\tint status = 0;\n")
+ fmt.Fprint(w, "\twhile (waitpid(pid, &status, __WALL) != pid) {}\n")
+ } else {
+ if opts.EnableTun {
+ fmt.Fprintf(w, "\tsetup_tun(0, %v);\n", opts.EnableTun)
+ }
+ fmt.Fprint(w, "\tloop();\n")
+ }
fmt.Fprint(w, "\treturn 0;\n}\n")
} else {
generateTestFunc(w, opts, calls, "test")
@@ -100,9 +107,16 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) {
if opts.UseTmpDir {
fmt.Fprintf(w, "\tuse_temporary_dir();\n")
}
- fmt.Fprintf(w, "\tint pid = do_sandbox_%v(0, %v);\n", opts.Sandbox, opts.EnableTun)
- fmt.Fprint(w, "\tint status = 0;\n")
- fmt.Fprint(w, "\twhile (waitpid(pid, &status, __WALL) != pid) {}\n")
+ if opts.Sandbox != "" {
+ fmt.Fprintf(w, "\tint pid = do_sandbox_%v(0, %v);\n", opts.Sandbox, opts.EnableTun)
+ fmt.Fprint(w, "\tint status = 0;\n")
+ fmt.Fprint(w, "\twhile (waitpid(pid, &status, __WALL) != pid) {}\n")
+ } else {
+ if opts.EnableTun {
+ fmt.Fprintf(w, "\tsetup_tun(0, %v);\n", opts.EnableTun)
+ }
+ fmt.Fprint(w, "\tloop();\n")
+ }
fmt.Fprint(w, "\treturn 0;\n}\n")
} else {
fmt.Fprint(w, "int main()\n{\n")
@@ -115,9 +129,16 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) {
if opts.UseTmpDir {
fmt.Fprintf(w, "\t\t\tuse_temporary_dir();\n")
}
- fmt.Fprintf(w, "\t\t\tint pid = do_sandbox_%v(i, %v);\n", opts.Sandbox, opts.EnableTun)
- fmt.Fprint(w, "\t\t\tint status = 0;\n")
- fmt.Fprint(w, "\t\t\twhile (waitpid(pid, &status, __WALL) != pid) {}\n")
+ if opts.Sandbox != "" {
+ fmt.Fprintf(w, "\t\t\tint pid = do_sandbox_%v(i, %v);\n", opts.Sandbox, opts.EnableTun)
+ fmt.Fprint(w, "\t\t\tint status = 0;\n")
+ fmt.Fprint(w, "\t\t\twhile (waitpid(pid, &status, __WALL) != pid) {}\n")
+ } else {
+ if opts.EnableTun {
+ fmt.Fprintf(w, "\t\t\tsetup_tun(i, %v);\n", opts.EnableTun)
+ }
+ fmt.Fprint(w, "\t\t\tloop();\n")
+ }
fmt.Fprint(w, "\t\t\treturn 0;\n")
fmt.Fprint(w, "\t\t}\n")
fmt.Fprint(w, "\t}\n")
@@ -334,6 +355,8 @@ func preprocessCommonHeader(opts Options, handled map[string]int, useBitmasks bo
defines = append(defines, "SYZ_USE_BITMASKS")
}
switch opts.Sandbox {
+ case "":
+ // No sandbox, do nothing.
case "none":
defines = append(defines, "SYZ_SANDBOX_NONE")
case "setuid":