diff options
author | Jeff Sharkey <jsharkey@android.com> | 2014-08-06 01:23:28 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-08-06 01:23:28 +0000 |
commit | 8c9b155ea17c8281021d835fc1f5fedc49199c4b (patch) | |
tree | d5ab9d38419967acfc8217a524554891c17ac281 /adb | |
parent | fea59faa01a3470974599728f8e8d3a96fb173fa (diff) | |
parent | 43d65b6903249a409031b081bb6175b9ad3e5c2a (diff) | |
download | system_core-8c9b155ea17c8281021d835fc1f5fedc49199c4b.zip system_core-8c9b155ea17c8281021d835fc1f5fedc49199c4b.tar.gz system_core-8c9b155ea17c8281021d835fc1f5fedc49199c4b.tar.bz2 |
am 43d65b69: Merge "Escape single quotes in arguments." into lmp-dev
* commit '43d65b6903249a409031b081bb6175b9ad3e5c2a':
Escape single quotes in arguments.
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; |