From d2b588e23901538f4b459a71fefdac6fc2748f7e Mon Sep 17 00:00:00 2001 From: David Pursell Date: Fri, 25 Sep 2015 13:04:21 -0700 Subject: [PATCH] adb: fix adbd feature parsing for no features. Previously the transport features list was only overwritten if a new feature list was found. However, adbd can reuse the same atransport object even if the adb server is killed and restarted, so the feature list was not cleared properly if the newly started adb server didn't provide one. This CL fixes the bug by clearing the transport features list whenever a connection banner is parsed. Bug: http://b/24405971 Change-Id: Ia6ee6c9a46a621534681f6d4d7df77156b885eb9 --- adb/adb.cpp | 4 ++++ adb/transport.cpp | 4 ++++ adb/transport_test.cpp | 3 +++ 3 files changed, 11 insertions(+) diff --git a/adb/adb.cpp b/adb/adb.cpp index e97360339..0e1859cdd 100644 --- a/adb/adb.cpp +++ b/adb/adb.cpp @@ -239,6 +239,10 @@ void parse_banner(const std::string& banner, atransport* t) { // "device::ro.product.name=x;ro.product.model=y;ro.product.device=z;". std::vector pieces = android::base::Split(banner, ":"); + // Reset the features list or else if the server sends no features we may + // keep the existing feature set (http://b/24405971). + t->SetFeatures(""); + if (pieces.size() > 2) { const std::string& props = pieces[2]; for (auto& prop : android::base::Split(props, ";")) { diff --git a/adb/transport.cpp b/adb/transport.cpp index ffbb10798..6ebb9c728 100644 --- a/adb/transport.cpp +++ b/adb/transport.cpp @@ -796,6 +796,10 @@ std::string FeatureSetToString(const FeatureSet& features) { } FeatureSet StringToFeatureSet(const std::string& features_string) { + if (features_string.empty()) { + return FeatureSet(); + } + auto names = android::base::Split(features_string, {kFeatureStringDelimiter}); return FeatureSet(names.begin(), names.end()); diff --git a/adb/transport_test.cpp b/adb/transport_test.cpp index 7d69c3ea7..97fc0698d 100644 --- a/adb/transport_test.cpp +++ b/adb/transport_test.cpp @@ -167,6 +167,9 @@ TEST(transport, SetFeatures) { ASSERT_FALSE(t.has_feature("foo")); ASSERT_TRUE(t.has_feature("bar")); ASSERT_TRUE(t.has_feature("baz")); + + t.SetFeatures(""); + ASSERT_EQ(0U, t.features().size()); } TEST(transport, parse_banner_no_features) { -- 2.11.0