Skip to content

Commit

Permalink
fix: crash when invoking login callback synchronously (#30068)
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed Jul 12, 2021
1 parent d09e7f8 commit 7aeae89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/npm-run.py
Expand Up @@ -16,5 +16,5 @@
subprocess.check_output(args, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
error_msg = "NPM script '{}' failed with code '{}':\n".format(sys.argv[2], e.returncode)
print(error_msg + e.output.decode('ascii'))
print(error_msg + e.output.decode('utf8'))
sys.exit(e.returncode)
6 changes: 5 additions & 1 deletion shell/browser/login_handler.cc
Expand Up @@ -69,11 +69,15 @@ void LoginHandler::EmitEvent(
details.Set("firstAuthAttempt", first_auth_attempt);
details.Set("responseHeaders", response_headers.get());

auto weak_this = weak_factory_.GetWeakPtr();
bool default_prevented =
api_web_contents->Emit("login", std::move(details), auth_info,
base::BindOnce(&LoginHandler::CallbackFromJS,
weak_factory_.GetWeakPtr()));
if (!default_prevented && auth_required_callback_) {
// ⚠️ NB, if CallbackFromJS is called during Emit(), |this| will have been
// deleted. Check the weak ptr before accessing any member variables to
// prevent UAF.
if (weak_this && !default_prevented && auth_required_callback_) {
std::move(auth_required_callback_).Run(base::nullopt);
}
}
Expand Down

0 comments on commit 7aeae89

Please sign in to comment.