summaryrefslogtreecommitdiff
path: root/adb_client.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-04-27 14:20:17 -0700
committerElliott Hughes <enh@google.com>2015-04-27 14:52:17 -0700
commit34f00fcfa21941629a7177ed401b1358a920c6b9 (patch)
tree79a717f47ad9c055e176bcd8da18a0d50e034d55 /adb_client.cpp
parentb4918ca686443e41ec2583d937a4a78cf9705a2c (diff)
downloadadb-34f00fcfa21941629a7177ed401b1358a920c6b9.tar.gz
Support the full length of USB serial numbers.
Two bugs: we couldn't report the serial number correctly if it was long enough, and it wasn't possible to connect to a device whose serial number was long enough to overflow a different fixed-length buffer. Bug: http://b/20317730 Change-Id: Ic9cf3c847066449ac78069bd1718184935098ac7
Diffstat (limited to 'adb_client.cpp')
-rw-r--r--adb_client.cpp54
1 files changed, 26 insertions, 28 deletions
diff --git a/adb_client.cpp b/adb_client.cpp
index 4751bff..0f64998 100644
--- a/adb_client.cpp
+++ b/adb_client.cpp
@@ -28,6 +28,8 @@
#include <sys/stat.h>
#include <sys/types.h>
+#include <string>
+
#include "adb_io.h"
static transport_type __adb_transport = kTransportAny;
@@ -108,44 +110,40 @@ const char *adb_error(void)
static int switch_socket_transport(int fd)
{
- char service[64];
- char tmp[5];
- int len;
-
- if (__adb_serial)
- snprintf(service, sizeof service, "host:transport:%s", __adb_serial);
- else {
+ std::string service;
+ if (__adb_serial) {
+ service += "host:transport:";
+ service += __adb_serial;
+ } else {
const char* transport_type = "???";
-
- switch (__adb_transport) {
- case kTransportUsb:
- transport_type = "transport-usb";
- break;
- case kTransportLocal:
- transport_type = "transport-local";
- break;
- case kTransportAny:
- transport_type = "transport-any";
- break;
- case kTransportHost:
- // no switch necessary
- return 0;
- break;
+ switch (__adb_transport) {
+ case kTransportUsb:
+ transport_type = "transport-usb";
+ break;
+ case kTransportLocal:
+ transport_type = "transport-local";
+ break;
+ case kTransportAny:
+ transport_type = "transport-any";
+ break;
+ case kTransportHost:
+ // no switch necessary
+ return 0;
}
-
- snprintf(service, sizeof service, "host:%s", transport_type);
+ service += "host:";
+ service += transport_type;
}
- len = strlen(service);
- snprintf(tmp, sizeof tmp, "%04x", len);
- if(!WriteFdExactly(fd, tmp, 4) || !WriteFdExactly(fd, service, len)) {
+ char tmp[5];
+ snprintf(tmp, sizeof(tmp), "%04zx", service.size());
+ if (!WriteFdExactly(fd, tmp, 4) || !WriteFdExactly(fd, service.c_str(), service.size())) {
strcpy(__adb_error, "write failure during connection");
adb_close(fd);
return -1;
}
D("Switch transport in progress\n");
- if(adb_status(fd)) {
+ if (adb_status(fd)) {
adb_close(fd);
D("Switch transport failed\n");
return -1;