Skip to content
forked from v8/v8

Commit

Permalink
[M108-LTS][inspector] Prevent regex breakpoints from re-entering the …
Browse files Browse the repository at this point in the history
…debugger

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

(cherry picked from commit 92a918e)

Bug: chromium:1426163, chromium:1422830
Change-Id: I4eb7873645a02c286664e0b6ddb53b9fb7db64f6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4355440
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#86621}
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4707112
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Reviewed-by: Jana Grill <janagrill@google.com>
Commit-Queue: Zakhar Voit <voit@google.com>
Cr-Commit-Position: refs/branch-heads/10.8@{v8#78}
Cr-Branched-From: f1bc03f-refs/heads/10.8.168@{#1}
Cr-Branched-From: 237de89-refs/heads/main@{#83672}
  • Loading branch information
zakharvoit authored and V8 LUCI CQ committed Jul 24, 2023
1 parent 9953b12 commit 33fd414
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 @@ -609,6 +609,9 @@ Response V8DebuggerAgentImpl::setBreakpointByUrl(
String16 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());
if (!hint.isEmpty()) {
adjustBreakpointLocation(*script.second, hint, &lineNumber,
&columnNumber);
Expand Down Expand Up @@ -742,6 +745,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 @@ -1898,6 +1904,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);
String16 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(isolate,
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 33fd414

Please sign in to comment.