Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/mono/mono/component/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -9324,7 +9324,7 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
names = g_new (char *, sig->param_count);
mono_method_get_param_names_internal (method, (const char **) names);
for (guint16 i = 0; i < sig->param_count; ++i)
buffer_add_string (buf, names [i]);
buffer_add_string (buf, names [i] ? names [i] : "");
g_free (names);

break;
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ mono_method_get_param_names_internal (MonoMethod *method, const char **names)
return;

for (i = 0; i < signature->param_count; ++i)
names [i] = "";
names [i] = NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mono_method_get_param_names_internal is called by a couple of other methods. We need to make sure that each of them expects and handles NULL value. This seems to produce quite a few crashes on CI, primarily around aot compilation, but it looks like debugger could also suffer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrzVlad Thank you for catching this! I've audited all callers of mono_method_get_param_names_internal and found 2 unsafe callers
debugger-agent.c:9327 - Added NULL check: names[i] ? names[i] : ""
dwarfwriter.c:1868 - Added NULL check: !pname || pname[0] == '\0'

and other callers (mini-llvm.c (lines 4168, 13298) - checks if (names[i]), debug-mini.c:680 - uses ternary names[i] ? names[i] : "unknown name"

already loosk safe
Please let me know if I'm missing something here or if there are other callers I should check.


klass = method->klass;
if (m_class_get_rank (klass))
Expand Down
9 changes: 7 additions & 2 deletions src/mono/mono/metadata/reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,13 @@ add_parameter_object_to_array (MonoMethod *method, MonoObjectHandle member, int
goto_if_nok (error, leave);

MonoStringHandle name_str;
name_str = mono_string_new_handle (name, error);
goto_if_nok (error, leave);
if (name != NULL) {
name_str = mono_string_new_handle (name, error);
goto_if_nok (error, leave);
} else {
// Keep NULL as NULL instead of converting to empty string
name_str = MONO_HANDLE_NEW (MonoString, NULL);
}

MonoObjectHandle def_value;

Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/dwarfwriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,7 @@ mono_dwarf_writer_emit_method (MonoDwarfWriter *w, MonoCompile *cfg, MonoMethod

emit_uleb128 (w, need_loclist ? ABBREV_PARAM_LOCLIST : ABBREV_PARAM);
/* name */
if (pname[0] == '\0') {
if (!pname || pname[0] == '\0') {
sprintf (pname_buf, "param%d", i - sig->hasthis);
pname = pname_buf;
}
Expand Down