aboutsummaryrefslogtreecommitdiffstats
path: root/csource
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@google.com>2017-05-18 14:26:02 +0200
committerAndrey Konovalov <andreyknvl@google.com>2017-06-12 19:48:23 +0200
commit5597911fbf26237b9d11a0f6293e4b52b2d9069c (patch)
tree9559a1e14daff7759f4ba6ef6740c6809567d081 /csource
parente7366c123e8e62cab5e70998b56e832c77178a59 (diff)
csource: use tmp dir only when necessary
Diffstat (limited to 'csource')
-rw-r--r--csource/common.go5
-rw-r--r--csource/csource.go16
-rw-r--r--csource/csource_test.go24
3 files changed, 30 insertions, 15 deletions
diff --git a/csource/common.go b/csource/common.go
index 048df6f52..8fa531598 100644
--- a/csource/common.go
+++ b/csource/common.go
@@ -150,7 +150,9 @@ static void install_segv_handler()
sigaction(SIGBUS, &sa, NULL);
}
-static void use_temporary_dir() {
+#if defined(SYZ_EXECUTOR) || defined(SYZ_USE_TMP_DIR)
+static void use_temporary_dir()
+{
char tmpdir_template[] = "./syzkaller.XXXXXX";
char* tmpdir = mkdtemp(tmpdir_template);
if (!tmpdir)
@@ -160,6 +162,7 @@ static void use_temporary_dir() {
if (chdir(tmpdir))
fail("failed to chdir");
}
+#endif
#define NONFAILING(...) \
{ \
diff --git a/csource/csource.go b/csource/csource.go
index b41c5ca11..bc50bf2ea 100644
--- a/csource/csource.go
+++ b/csource/csource.go
@@ -34,6 +34,7 @@ type Options struct {
// These options allow for a more fine-tuned control over the generated C code.
EnableTun bool
+ UseTmpDir bool
// Generate code for use with repro package to prints log messages,
// which allows to distinguish between a hang and an absent crash.
@@ -75,7 +76,9 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) {
fmt.Fprint(w, "int main()\n{\n")
fmt.Fprintf(w, "\tinstall_segv_handler();\n")
- fmt.Fprintf(w, "\tuse_temporary_dir();\n")
+ 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")
@@ -85,7 +88,9 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) {
if opts.Procs <= 1 {
fmt.Fprint(w, "int main()\n{\n")
fmt.Fprintf(w, "\tinstall_segv_handler();\n")
- fmt.Fprintf(w, "\tuse_temporary_dir();\n")
+ 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")
@@ -96,7 +101,9 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) {
fmt.Fprintf(w, "\tfor (i = 0; i < %v; i++) {\n", opts.Procs)
fmt.Fprint(w, "\t\tif (fork() == 0) {\n")
fmt.Fprintf(w, "\t\t\tinstall_segv_handler();\n")
- fmt.Fprintf(w, "\t\t\tuse_temporary_dir();\n")
+ 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")
@@ -327,6 +334,9 @@ func preprocessCommonHeader(opts Options, handled map[string]int) (string, error
if opts.EnableTun {
defines = append(defines, "SYZ_TUN_ENABLE")
}
+ if opts.UseTmpDir {
+ defines = append(defines, "SYZ_USE_TMP_DIR")
+ }
for name, _ := range handled {
defines = append(defines, "__NR_"+name)
}
diff --git a/csource/csource_test.go b/csource/csource_test.go
index 8ca7bb5ce..3e09a3019 100644
--- a/csource/csource_test.go
+++ b/csource/csource_test.go
@@ -35,18 +35,20 @@ func allOptionsPermutations() []Options {
for _, opt.Procs = range []int{1, 4} {
for _, opt.Sandbox = range []string{"none", "setuid", "namespace"} {
for _, opt.Repro = range []bool{false, true} {
- for _, opt.EnableTun = range []bool{false, true} {
- for _, opt.Fault = range []bool{false, true} {
- if opt.Collide && !opt.Threaded {
- continue
+ for _, opt.Fault = range []bool{false, true} {
+ for _, opt.EnableTun = range []bool{false, true} {
+ for _, opt.UseTmpDir = range []bool{false, true} {
+ if opt.Collide && !opt.Threaded {
+ continue
+ }
+ if !opt.Repeat && opt.Procs != 1 {
+ continue
+ }
+ if testing.Short() && opt.Procs != 1 {
+ continue
+ }
+ options = append(options, opt)
}
- if !opt.Repeat && opt.Procs != 1 {
- continue
- }
- if testing.Short() && opt.Procs != 1 {
- continue
- }
- options = append(options, opt)
}
}
}