Skip to content
forked from v8/v8

Commit

Permalink
[inspector] Prevent regex breakpoints from re-entering the debugger
Browse files Browse the repository at this point in the history
This patch uses the postpone-interrupts scope to prevent regexes
from re-entering the debugger when matching regex breakpoints
(while setting or removing regex breakpoints).

The test is separate in a Blink CL: crrev.com/c/4355146

Bug: chromium:1426163
Change-Id: I4eb7873645a02c286664e0b6ddb53b9fb7db64f6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4355440
Reviewed-by: Simon Zünd <szuend@chromium.org>
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#86621}
  • Loading branch information
jaro-sevcik authored and V8 LUCI CQ committed Mar 22, 2023
1 parent a7d3bfe commit 92a918e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/inspector/v8-debugger-agent-impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ Response V8DebuggerAgentImpl::setBreakpointByUrl(
std::unique_ptr<protocol::DictionaryValue> hint;
for (const auto& script : m_scripts) {
if (!matcher.matches(*script.second)) continue;
// Make sure the session was not disabled by some re-entrant call
// in the script matcher.
DCHECK(enabled());
int adjustedLineNumber = lineNumber;
int adjustedColumnNumber = columnNumber;
if (hint) {
Expand Down Expand Up @@ -810,6 +813,9 @@ Response V8DebuggerAgentImpl::removeBreakpoint(const String16& breakpointId) {
std::vector<V8DebuggerScript*> scripts;
for (const auto& scriptIter : m_scripts) {
const bool scriptSelectorMatch = matcher.matches(*scriptIter.second);
// Make sure the session was not disabled by some re-entrant call
// in the script matcher.
DCHECK(enabled());
const bool isInstrumentation =
type == BreakpointType::kInstrumentationBreakpoint;
if (!scriptSelectorMatch && !isInstrumentation) continue;
Expand Down Expand Up @@ -1980,6 +1986,9 @@ void V8DebuggerAgentImpl::didParseSource(
Matcher matcher(m_inspector, type, selector);

if (!matcher.matches(*scriptRef)) continue;
// Make sure the session was not disabled by some re-entrant call
// in the script matcher.
DCHECK(enabled());
String16 condition;
breakpointWithCondition.second->asString(&condition);
protocol::DictionaryValue* hint =
Expand Down
4 changes: 4 additions & 0 deletions src/inspector/v8-regex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ V8Regex::V8Regex(V8InspectorImpl* inspector, const String16& pattern,
if (multiline) flags |= v8::RegExp::kMultiline;

v8::Local<v8::RegExp> regex;
// Protect against reentrant debugger calls via interrupts.
v8::debug::PostponeInterruptsScope no_interrupts(m_inspector->isolate());
if (v8::RegExp::New(context, toV8String(isolate, pattern),
static_cast<v8::RegExp::Flags>(flags))
.ToLocal(&regex))
Expand Down Expand Up @@ -65,6 +67,8 @@ int V8Regex::match(const String16& string, int startFrom,
v8::Context::Scope contextScope(context);
v8::MicrotasksScope microtasks(context,
v8::MicrotasksScope::kDoNotRunMicrotasks);
// Protect against reentrant debugger calls via interrupts.
v8::debug::PostponeInterruptsScope no_interrupts(m_inspector->isolate());
v8::TryCatch tryCatch(isolate);

v8::Local<v8::RegExp> regex = m_regex.Get(isolate);
Expand Down

0 comments on commit 92a918e

Please sign in to comment.