diff options
| author | Joey Jiao <joeyjiaojg@gmail.com> | 2021-03-29 14:37:22 +0800 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2021-04-14 19:04:39 +0200 |
| commit | e40a490e9c5e71bb3c0aca2a1ddcf7af4845635d (patch) | |
| tree | 96fb8d65e2b684cd46c579a58a7c20dd5f0e3e39 /vm/vmimpl | |
| parent | 5c9ed2bcc8d10336c1389d63db51a4bde97b16a0 (diff) | |
vm/adb: add startup_script config
Diffstat (limited to 'vm/vmimpl')
| -rw-r--r-- | vm/vmimpl/vmimpl.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/vm/vmimpl/vmimpl.go b/vm/vmimpl/vmimpl.go index b3b7b19e4..854bef0a0 100644 --- a/vm/vmimpl/vmimpl.go +++ b/vm/vmimpl/vmimpl.go @@ -14,6 +14,7 @@ import ( "math/rand" "net" "os/exec" + "strings" "time" "github.com/google/syzkaller/pkg/log" @@ -181,3 +182,43 @@ func UnusedTCPPort() int { } } } + +// Escapes double quotes(and nested double quote escapes). Ignores any other escapes. +// Reference: https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html +func EscapeDoubleQuotes(inp string) string { + var ret strings.Builder + for pos := 0; pos < len(inp); pos++ { + // If inp[pos] is not a double quote or a backslash, just use + // as is. + if inp[pos] != '"' && inp[pos] != '\\' { + ret.WriteByte(inp[pos]) + continue + } + // If it is a double quote, escape. + if inp[pos] == '"' { + ret.WriteString("\\\"") + continue + } + // If we detect a backslash, reescape only if what it's already escaping + // is a double-quotes. + temp := "" + j := pos + for ; j < len(inp); j++ { + if inp[j] == '\\' { + temp += string(inp[j]) + continue + } + // If the escape corresponds to a double quotes, re-escape. + // Else, just use as is. + if inp[j] == '"' { + temp = temp + temp + "\\\"" + } else { + temp += string(inp[j]) + } + break + } + ret.WriteString(temp) + pos = j + } + return ret.String() +} |
