Skip to content

[mono][debugger] Fix infinite recursion and null pointer access while debugging #73024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/mono/mono/component/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -4069,7 +4069,7 @@ jit_end (MonoProfiler *prof, MonoMethod *method, MonoJitInfo *jinfo)

// only send typeload from AOTed classes if has .cctor when .cctor emits jit_end
// to avoid deadlock while trying to set a breakpoint in a class that was not fully initialized
if (jinfo->from_aot && m_class_has_cctor(method->klass) && (!(method->flags & METHOD_ATTRIBUTE_SPECIAL_NAME) || strcmp (method->name, ".cctor")))
if (jinfo && jinfo->from_aot && m_class_has_cctor(method->klass) && (!(method->flags & METHOD_ATTRIBUTE_SPECIAL_NAME) || strcmp (method->name, ".cctor")))
{
return;
}
Expand Down Expand Up @@ -5195,6 +5195,17 @@ buffer_add_value_full (Buffer *buf, MonoType *t, void *addr, MonoDomain *domain,
continue;
if (mono_field_is_deleted (f))
continue;

if (mono_vtype_get_field_addr (addr, f) == addr) //to avoid infinite recursion
{
gssize val = *(gssize*)addr;
buffer_add_byte (buf, MONO_TYPE_PTR);
buffer_add_long (buf, val);
if (CHECK_PROTOCOL_VERSION(2, 46))
buffer_add_typeid (buf, domain, mono_class_from_mono_type_internal (t));
continue;
}

buffer_add_value_full (buf, f->type, mono_vtype_get_field_addr (addr, f), domain, FALSE, parent_vtypes, len_fixed_array != 1 ? len_fixed_array : isFixedSizeArray(f));
}

Expand Down
17 changes: 17 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,5 +1022,22 @@ await EvaluateAndCheck(
method_name_call_stack
);
}

[Fact]
public async Task InspectLocalRecursiveFieldValue()
{
var expression = $"{{ invoke_static_method('[debugger-test] InspectIntPtr:Run'); }}";

await EvaluateAndCheck(
"window.setTimeout(function() {" + expression + "; }, 1);",
"dotnet://debugger-test.dll/debugger-test.cs", 1256, 8,
$"InspectIntPtr.Run",
locals_fn: async (locals) =>
{
await CheckValueType(locals, "myInt", "System.IntPtr");
await CheckValueType(locals, "myInt2", "System.IntPtr");
}
);
}
}
}
10 changes: 10 additions & 0 deletions src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,3 +1247,13 @@ public static async void TestKlassGenericAsyncGeneric6()
}
}

public class InspectIntPtr
{
public static void Run()
{
IntPtr myInt = default;
IntPtr myInt2 = new IntPtr(1);

System.Diagnostics.Debugger.Break();
}
}