summaryrefslogtreecommitdiffstats
path: root/adb
diff options
context:
space:
mode:
Diffstat (limited to 'adb')
-rw-r--r--adb/adb.c10
-rw-r--r--adb/commandline.c64
2 files changed, 33 insertions, 41 deletions
diff --git a/adb/adb.c b/adb/adb.c
index 2c7793d..10a1e0d 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -1670,11 +1670,6 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
/* we don't even need to send a reply */
return 0;
}
-#endif // ADB_HOST
-
- int ret = handle_forward_request(service, ttype, serial, reply_fd);
- if (ret >= 0)
- return ret - 1;
if(!strncmp(service,"get-state",strlen("get-state"))) {
transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
@@ -1682,6 +1677,11 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
send_msg_with_okay(reply_fd, state, strlen(state));
return 0;
}
+#endif // ADB_HOST
+
+ int ret = handle_forward_request(service, ttype, serial, reply_fd);
+ if (ret >= 0)
+ return ret - 1;
return -1;
}
diff --git a/adb/commandline.c b/adb/commandline.c
index cb5e75d..356c0db 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -544,39 +544,40 @@ static void status_window(transport_type ttype, const char* serial)
}
}
-/** duplicate string and quote all \ " ( ) chars + space character. */
-static char *
-dupAndQuote(const char *s)
+/** Duplicate and escape given argument. */
+static char *escape_arg(const char *s)
{
const char *ts;
size_t alloc_len;
char *ret;
char *dest;
- ts = s;
-
alloc_len = 0;
-
- for( ;*ts != '\0'; ts++) {
+ for (ts = s; *ts != '\0'; ts++) {
alloc_len++;
if (*ts == ' ' || *ts == '"' || *ts == '\\' || *ts == '(' || *ts == ')') {
alloc_len++;
}
}
- ret = (char *)malloc(alloc_len + 1);
+ if (alloc_len == 0) {
+ // Preserve empty arguments
+ ret = (char *) malloc(3);
+ ret[0] = '\"';
+ ret[1] = '\"';
+ ret[2] = '\0';
+ return ret;
+ }
- ts = s;
+ ret = (char *) malloc(alloc_len + 1);
dest = ret;
- for ( ;*ts != '\0'; ts++) {
+ for (ts = s; *ts != '\0'; ts++) {
if (*ts == ' ' || *ts == '"' || *ts == '\\' || *ts == '(' || *ts == ')') {
*dest++ = '\\';
}
-
*dest++ = *ts;
}
-
*dest++ = '\0';
return ret;
@@ -683,30 +684,24 @@ static int logcat(transport_type transport, char* serial, int argc, char **argv)
char buf[4096];
char *log_tags;
- char *quoted_log_tags;
+ char *quoted;
log_tags = getenv("ANDROID_LOG_TAGS");
- quoted_log_tags = dupAndQuote(log_tags == NULL ? "" : log_tags);
-
+ quoted = escape_arg(log_tags == NULL ? "" : log_tags);
snprintf(buf, sizeof(buf),
- "shell:export ANDROID_LOG_TAGS=\"\%s\" ; exec logcat",
- quoted_log_tags);
-
- free(quoted_log_tags);
+ "shell:export ANDROID_LOG_TAGS=\"%s\"; exec logcat", quoted);
+ free(quoted);
- if (!strcmp(argv[0],"longcat")) {
- strncat(buf, " -v long", sizeof(buf)-1);
+ if (!strcmp(argv[0], "longcat")) {
+ strncat(buf, " -v long", sizeof(buf) - 1);
}
argc -= 1;
argv += 1;
while(argc-- > 0) {
- char *quoted;
-
- quoted = dupAndQuote (*argv++);
-
- strncat(buf, " ", sizeof(buf)-1);
- strncat(buf, quoted, sizeof(buf)-1);
+ quoted = escape_arg(*argv++);
+ strncat(buf, " ", sizeof(buf) - 1);
+ strncat(buf, quoted, sizeof(buf) - 1);
free(quoted);
}
@@ -1218,7 +1213,7 @@ top:
argc -= 2;
argv += 2;
while (argc-- > 0) {
- char *quoted = dupAndQuote(*argv++);
+ char *quoted = escape_arg(*argv++);
strncat(buf, " ", sizeof(buf) - 1);
strncat(buf, quoted, sizeof(buf) - 1);
free(quoted);
@@ -1261,7 +1256,7 @@ top:
argc -= 2;
argv += 2;
while (argc-- > 0) {
- char *quoted = dupAndQuote(*argv++);
+ char *quoted = escape_arg(*argv++);
strncat(buf, " ", sizeof(buf) - 1);
strncat(buf, quoted, sizeof(buf) - 1);
free(quoted);
@@ -1689,12 +1684,9 @@ static int pm_command(transport_type transport, char* serial,
snprintf(buf, sizeof(buf), "shell:pm");
while(argc-- > 0) {
- char *quoted;
-
- quoted = dupAndQuote(*argv++);
-
- strncat(buf, " ", sizeof(buf)-1);
- strncat(buf, quoted, sizeof(buf)-1);
+ char *quoted = escape_arg(*argv++);
+ strncat(buf, " ", sizeof(buf) - 1);
+ strncat(buf, quoted, sizeof(buf) - 1);
free(quoted);
}
@@ -1726,7 +1718,7 @@ static int delete_file(transport_type transport, char* serial, char* filename)
char* quoted;
snprintf(buf, sizeof(buf), "shell:rm ");
- quoted = dupAndQuote(filename);
+ quoted = escape_arg(filename);
strncat(buf, quoted, sizeof(buf)-1);
free(quoted);