diff options
author | Jeff Sharkey <jsharkey@android.com> | 2014-08-05 16:53:08 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2014-08-05 16:53:25 -0700 |
commit | d0eee747f6389a5800b485f36b265b3f5521852f (patch) | |
tree | 198a037da809627e179c4ed6c66fe201e56a03f0 /adb | |
parent | 3679d5f49a1e3caf69fffd1afa2d6139a0bfbb17 (diff) | |
download | system_core-d0eee747f6389a5800b485f36b265b3f5521852f.zip system_core-d0eee747f6389a5800b485f36b265b3f5521852f.tar.gz system_core-d0eee747f6389a5800b485f36b265b3f5521852f.tar.bz2 |
Escape single quotes in arguments.
Verified that these use-cases continue working:
$ adb shell arg a a 'b b'
$ adb shell arg a a "b b"
|arg|a|a|b b|
$ adb shell arg "a a 'b b'"
|arg|a a 'b b'|
$ adb shell arg 'a a "b b"'
|arg|a a "b b"|
$ adb shell arg a\"b\'c
|arg|a"b'c|
$ adb shell "arg a && arg b"
|arg|a|
|arg|b|
$ adb shell "arg 'a' \"b\" c"
|arg|a|b|c|
Bug: 16139781
Change-Id: I3b010b6cdf57281695c11fda318c9bea0a7221cc
Diffstat (limited to 'adb')
-rw-r--r-- | adb/commandline.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/adb/commandline.c b/adb/commandline.c index e1ff856..af21e38 100644 --- a/adb/commandline.c +++ b/adb/commandline.c @@ -675,7 +675,12 @@ static void status_window(transport_type ttype, const char* serial) } } -/** Duplicate and escape given argument. */ +static bool should_escape(const char c) +{ + return (c == ' ' || c == '\'' || c == '"' || c == '\\' || c == '(' || c == ')'); +} + +/* Duplicate and escape given argument. */ static char *escape_arg(const char *s) { const char *ts; @@ -686,7 +691,7 @@ static char *escape_arg(const char *s) alloc_len = 0; for (ts = s; *ts != '\0'; ts++) { alloc_len++; - if (*ts == ' ' || *ts == '"' || *ts == '\\' || *ts == '(' || *ts == ')') { + if (should_escape(*ts)) { alloc_len++; } } @@ -704,7 +709,7 @@ static char *escape_arg(const char *s) dest = ret; for (ts = s; *ts != '\0'; ts++) { - if (*ts == ' ' || *ts == '"' || *ts == '\\' || *ts == '(' || *ts == ')') { + if (should_escape(*ts)) { *dest++ = '\\'; } *dest++ = *ts; |