From 080c004a20ead6229e2bef1a04f30c6cbf44a0c0 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 30 Apr 2015 17:32:03 -0700 Subject: More adb buffer fixes. This patch factors out a lot of the basic protocol code: sending OKAY, sending FAIL, and sending a length-prefixed string. ADB_TRACE has been non-optional for a long time, so let's just remove the #ifs. Also actually build the device tracker test tool (and remove its duplicate). Bug: http://b/20666660 Change-Id: I6c7d59f18707bdc62ca69dea45547617f9f31fc6 --- adb_client.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'adb_client.cpp') diff --git a/adb_client.cpp b/adb_client.cpp index 62f79fa..33eee82 100644 --- a/adb_client.cpp +++ b/adb_client.cpp @@ -56,7 +56,7 @@ static bool ReadProtocolString(int fd, std::string* s, std::string* error) { buf[4] = 0; unsigned long len = strtoul(buf, 0, 16); - s->resize(len + 1, '\0'); // Ensure NUL-termination. + s->resize(len, '\0'); if (!ReadFdExactly(fd, &(*s)[0], len)) { *error = perror_str("protocol fault (couldn't read status message)"); return false; @@ -136,9 +136,7 @@ static int switch_socket_transport(int fd, std::string* error) { service += transport_type; } - char tmp[5]; - snprintf(tmp, sizeof(tmp), "%04zx", service.size()); - if (!WriteFdExactly(fd, tmp, 4) || !WriteFdExactly(fd, service.c_str(), service.size())) { + if (!SendProtocolString(fd, service)) { *error = perror_str("write failure during connection"); adb_close(fd); return -1; @@ -199,9 +197,7 @@ int _adb_connect(const std::string& service, std::string* error) { return -1; } - char tmp[5]; - snprintf(tmp, sizeof(tmp), "%04zx", service.size()); - if(!WriteFdExactly(fd, tmp, 4) || !WriteFdExactly(fd, &service[0], service.size())) { + if(!SendProtocolString(fd, service)) { *error = perror_str("write failure during connection"); adb_close(fd); return -1; -- cgit v1.2.3