summaryrefslogtreecommitdiff
path: root/fastboot/tcp.cpp
diff options
context:
space:
mode:
authorDavid Pursell <dpursell@google.com>2016-02-17 10:00:09 -0800
committerDavid Pursell <dpursell@google.com>2016-02-17 10:00:09 -0800
commitaad72a533f97e8be5114e127fb681ee1596bdc89 (patch)
tree910a27ee2a76a93e9b23eefef13f29fc13286766 /fastboot/tcp.cpp
parent8c09555aac6f00cb7fa7d62cb5c356e2f07a268b (diff)
fastboot: fix TCP protocol version check.
Currently the TCP handshake fails if the device TCP protocol version doesn't match the host exactly, but the protocol is supposed to allow for forwards compatibility by accepting any protocol version >= itself. That way the other side can potentially lower its protocol to match and keep going. This CL fixes the protocol version check and adds corresponding unit tests. Bug: http://b/27220700 Change-Id: Ib17f0a55eb910105a27609bc94bf76a30442e92e
Diffstat (limited to 'fastboot/tcp.cpp')
-rw-r--r--fastboot/tcp.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/fastboot/tcp.cpp b/fastboot/tcp.cpp
index da2880a5e..e42c4e1af 100644
--- a/fastboot/tcp.cpp
+++ b/fastboot/tcp.cpp
@@ -28,6 +28,7 @@
#include "tcp.h"
+#include <android-base/parseint.h>
#include <android-base/stringprintf.h>
namespace tcp {
@@ -98,7 +99,8 @@ bool TcpTransport::InitializeProtocol(std::string* error) {
return false;
}
- char buffer[kHandshakeLength];
+ char buffer[kHandshakeLength + 1];
+ buffer[kHandshakeLength] = '\0';
if (socket_->ReceiveAll(buffer, kHandshakeLength, kHandshakeTimeoutMs) != kHandshakeLength) {
*error = android::base::StringPrintf(
"No initialization message received (%s). Target may not support TCP fastboot",
@@ -111,9 +113,10 @@ bool TcpTransport::InitializeProtocol(std::string* error) {
return false;
}
- if (memcmp(buffer + 2, "01", 2) != 0) {
+ int version = 0;
+ if (!android::base::ParseInt(buffer + 2, &version) || version < kProtocolVersion) {
*error = android::base::StringPrintf("Unknown TCP protocol version %s (host version %02d)",
- std::string(buffer + 2, 2).c_str(), kProtocolVersion);
+ buffer + 2, kProtocolVersion);
return false;
}