Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66d93d74 authored by Fabien Sanglard's avatar Fabien Sanglard Committed by Android (Google) Code Review
Browse files

Merge "Fix adbauth resetting the stack on unknown msg" into main

parents b95258d5 f8139257
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -151,8 +151,6 @@ void AdbdAuthContext::HandlePacket(std::string_view packet) EXCLUDES(mutex_) {
  }
  if (!handled_packet) {
    LOG(ERROR) << "adbd_auth: unhandled packet: " << packet;
    std::lock_guard<std::mutex> lock(mutex_);
    ReplaceFrameworkFd(unique_fd());
  }
}

+23 −1
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ class Framework {
    auto packet_id = runner->Context()->ReceivedPackets();
    Send(msg);

    while(runner->Context()->ReceivedPackets() < packet_id + 1) {
    while(runner->Context()->ReceivedPackets() == packet_id) {
      std::this_thread::sleep_for(10ms);
    }
  }
@@ -252,3 +252,25 @@ TEST(AdbAuthTest, WifiLifeCycle) {
    framework.SendAndWaitContext("W0", runner.get());
    ASSERT_EQ(stop_message_received,true);
}


TEST(AdbAuthTest, UnhandledPacket) {
    AdbdAuthCallbacksV2 callbacks{};
    callbacks.version = 2;
    auto runner= CreateContextRunner(callbacks);
    Framework framework{};

    uint16_t port = 19;
    adbd_auth_send_tls_server_port(runner->Context(), port);

    // Send an unhandled packet. This should not reset the stack.
    framework.SendAndWaitContext("XX", runner.get());

    // Check that libauth did not reset the socket.
    auto msg = framework.Recv();
    ASSERT_EQ(4, msg.size());
    ASSERT_EQ(msg[0], 'T');
    ASSERT_EQ(msg[1], 'P');
    ASSERT_EQ(msg[2], port);
    ASSERT_EQ(msg[3], 0);
}