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

Commit f8139257 authored by Fabien Sanglard's avatar Fabien Sanglard
Browse files

Fix adbauth resetting the stack on unknown msg

Even though adbdauth and Framework ship together, flagging may result in
Framework sending unknown messages to adbdauth. In this case the message
should merely be discarded (and logged) instead of closing the socket
and losing all other sockets.

Test: adbd_auth_test
Bug: NA
Flag: EXEMPT (bug fix)
Change-Id: I6bfeeabd1db4c736cb4e84c17e8f96b23ccc1e0a
parent 8e95fe85
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
@@ -138,7 +138,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);
    }
  }
@@ -253,3 +253,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);
}