aboutsummaryrefslogtreecommitdiffstats
path: root/prog/prog_test.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-07-08 17:35:15 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-07-08 22:52:24 +0200
commit1c667063a8d344ba09336ad43c69a2de5487f056 (patch)
tree2db9e4c2917f18cc770ad2ea850eb19fc2cef0d3 /prog/prog_test.go
parent306ca0571c5d906ce76df97bd1ea54f4e0e50240 (diff)
prog: don't generate filenames that escape sandbox
All files that fuzzer works with must be in the working dir. Using "/" is known to cause problems when fuzzer removes files there or mounts something.
Diffstat (limited to 'prog/prog_test.go')
-rw-r--r--prog/prog_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/prog/prog_test.go b/prog/prog_test.go
index e83310b32..5d4c2dac3 100644
--- a/prog/prog_test.go
+++ b/prog/prog_test.go
@@ -5,6 +5,7 @@ package prog
import (
"bytes"
+ "encoding/hex"
"fmt"
"math/rand"
"strings"
@@ -210,3 +211,36 @@ func TestSpecialStructs(t *testing.T) {
}
})
}
+
+func TestEscapingPaths(t *testing.T) {
+ paths := map[string]bool{
+ "/": true,
+ "/\x00": true,
+ "/file/..": true,
+ "/file/../..": true,
+ "./..": true,
+ "..": true,
+ "file/../../file": true,
+ "../file": true,
+ "./file/../../file/file": true,
+ "": false,
+ ".": false,
+ "file": false,
+ "./file": false,
+ "./file/..": false,
+ }
+ target, err := GetTarget("test", "64")
+ if err != nil {
+ t.Fatal(err)
+ }
+ for path, escaping := range paths {
+ text := fmt.Sprintf("mutate5(&(0x7f0000000000)=\"%s\", 0x0)", hex.EncodeToString([]byte(path)))
+ _, err := target.Deserialize([]byte(text))
+ if !escaping && err != nil {
+ t.Errorf("path %q is detected as escaping (%v)", path, err)
+ }
+ if escaping && (err == nil || !strings.Contains(err.Error(), "sandbox escaping file")) {
+ t.Errorf("path %q is not detected as escaping (%v)", path, err)
+ }
+ }
+}