summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2017-06-16 15:34:34 -0700
committerJosh Gao <jmgao@google.com>2017-06-16 18:01:11 -0700
commit9f9eaa4dfe984266bfa5e240b6b32d4dd8a41853 (patch)
tree94a784cae8aaa9ee8c3ba2859a2eb87de18639bc
parent405e49df62b64d4e45f1c037815a445e2faa4de3 (diff)
downloadadb-9f9eaa4dfe984266bfa5e240b6b32d4dd8a41853.tar.gz
adb: increase the shell command length limit.
Relax the shell command length limits when talking to an adbd with the shell protocol. shell is pretty much the only service that takes an arbitrarily long string, so this is somewhat safe. Bug: http://b/37716055 Test: `adb shell $(python -c 'print "echo " + "f" * (32*1024)') | wc` on L and master Change-Id: I0737fd2244530ef8080f300cd3a3549a1ab93465
-rw-r--r--adb_client.cpp2
-rw-r--r--adb_io.cpp2
-rw-r--r--commandline.cpp7
-rw-r--r--sockets.cpp2
-rw-r--r--test_device.py7
5 files changed, 17 insertions, 3 deletions
diff --git a/adb_client.cpp b/adb_client.cpp
index f5d0f02..e533a00 100644
--- a/adb_client.cpp
+++ b/adb_client.cpp
@@ -125,7 +125,7 @@ bool adb_status(int fd, std::string* error) {
static int _adb_connect(const std::string& service, std::string* error) {
D("_adb_connect: %s", service.c_str());
- if (service.empty() || service.size() > MAX_PAYLOAD_V1) {
+ if (service.empty() || service.size() > MAX_PAYLOAD) {
*error = android::base::StringPrintf("bad service name length (%zd)",
service.size());
return -1;
diff --git a/adb_io.cpp b/adb_io.cpp
index ca8729e..38e3116 100644
--- a/adb_io.cpp
+++ b/adb_io.cpp
@@ -31,7 +31,7 @@
bool SendProtocolString(int fd, const std::string& s) {
unsigned int length = s.size();
- if (length > MAX_PAYLOAD_V1 - 4) {
+ if (length > MAX_PAYLOAD - 4) {
errno = EMSGSIZE;
return false;
}
diff --git a/commandline.cpp b/commandline.cpp
index 68ae4af..c9f1ee9 100644
--- a/commandline.cpp
+++ b/commandline.cpp
@@ -599,6 +599,13 @@ static int RemoteShell(bool use_shell_protocol, const std::string& type_arg,
std::string service_string = ShellServiceString(use_shell_protocol,
type_arg, command);
+ // Old devices can't handle a service string that's longer than MAX_PAYLOAD_V1.
+ // Use |use_shell_protocol| to determine whether to allow a command longer than that.
+ if (service_string.size() > MAX_PAYLOAD_V1 && !use_shell_protocol) {
+ fprintf(stderr, "error: shell command too long\n");
+ return 1;
+ }
+
// Make local stdin raw if the device allocates a PTY, which happens if:
// 1. We are explicitly asking for a PTY shell, or
// 2. We don't specify shell type and are starting an interactive session.
diff --git a/sockets.cpp b/sockets.cpp
index 14ad1ff..e0143c6 100644
--- a/sockets.cpp
+++ b/sockets.cpp
@@ -686,7 +686,7 @@ static int smart_socket_enqueue(asocket* s, apacket* p) {
}
len = unhex(p->data, 4);
- if ((len < 1) || (len > MAX_PAYLOAD_V1)) {
+ if ((len < 1) || (len > MAX_PAYLOAD)) {
D("SS(%d): bad size (%d)", s->id, len);
goto fail;
}
diff --git a/test_device.py b/test_device.py
index 737d0c2..9e1a2ec 100644
--- a/test_device.py
+++ b/test_device.py
@@ -342,6 +342,13 @@ class ShellTest(DeviceTest):
out = self.device.shell(['echo', 'foo'])[0]
self.assertEqual(out, 'foo' + self.device.linesep)
+ def test_shell_command_length(self):
+ # Devices that have shell_v2 should be able to handle long commands.
+ if self.device.has_shell_protocol():
+ rc, out, err = self.device.shell_nocheck(['echo', 'x' * 16384])
+ self.assertEqual(rc, 0)
+ self.assertTrue(out == ('x' * 16384 + '\n'))
+
def test_shell_nocheck_failure(self):
rc, out, _ = self.device.shell_nocheck(['false'])
self.assertNotEqual(rc, 0)