diff options
author | Josh Gao <jmgao@google.com> | 2020-06-24 16:12:30 -0700 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2020-06-24 17:01:34 -0700 |
commit | 9653c9cf610ba5c241b7f29f2ddc2821e41d4d85 (patch) | |
tree | 7666f7d3050293d07fe9e109edb3c814a36fb488 | |
parent | 9e933c54793f56a9c66cba353d997a38d5598d9c (diff) | |
download | native-9653c9cf610ba5c241b7f29f2ddc2821e41d4d85.tar.gz |
adbd_auth: don't abort on unexpected response.
There seems to be an additional underlying bug that causes the framework
to send a spurious authentication denial, but this is still an
improvement.
Bug: http://b/159061108
Test: treehugger
Change-Id: I7028292fbde157f02cc35c3a37ab5c49d68eaae6
-rw-r--r-- | libs/adbd_auth/adbd_auth.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/libs/adbd_auth/adbd_auth.cpp b/libs/adbd_auth/adbd_auth.cpp index 0e5d474612..dae6eebaa5 100644 --- a/libs/adbd_auth/adbd_auth.cpp +++ b/libs/adbd_auth/adbd_auth.cpp @@ -206,12 +206,18 @@ public: void AllowUsbDevice(std::string_view buf) EXCLUDES(mutex_) { std::lock_guard<std::mutex> lock(mutex_); CHECK(buf.empty()); - CHECK(dispatched_prompt_.has_value()); - auto& [id, key, arg] = *dispatched_prompt_; - keys_.emplace(id, std::move(key)); - callbacks_.key_authorized(arg, id); - dispatched_prompt_ = std::nullopt; + if (dispatched_prompt_.has_value()) { + // It's possible for the framework to send us a response without our having sent a + // request to it: e.g. if adbd restarts while we have a pending request. + auto& [id, key, arg] = *dispatched_prompt_; + keys_.emplace(id, std::move(key)); + + callbacks_.key_authorized(arg, id); + dispatched_prompt_ = std::nullopt; + } else { + LOG(WARNING) << "adbd_auth: received authorization for unknown prompt, ignoring"; + } // We need to dispatch pending prompts here upon success as well, // since we might have multiple queued prompts. |