Bug 58888 - Crash rather than NullReferenceException for delegate with null target and virtual method
Summary: Crash rather than NullReferenceException for delegate with null target and vi...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: 5.0 (2017-02)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-08-18 19:05 UTC by Jonathan Chambers
Modified: 2017-08-21 14:39 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Repro (256 bytes, text/plain)
2017-08-18 19:05 UTC, Jonathan Chambers
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Jonathan Chambers 2017-08-18 19:05:27 UTC
Created attachment 24311 [details]
Repro

Run the following test case. .NET raises NullReferenceException when delegate function is accessed. Mono does not raise this exception, and later crashes trying to resolve the virtual method target:

.NET:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Program.Main(String[] args) in C:\dev\delete\ConsoleApplication1\ConsoleApplication1\Program.cs:line 8

Mono:
No exception then

Crash

>	mono-2.0-sgen.dll!mono_object_get_virtual_method(_MonoObject * obj_raw, _MonoMethod * method) Line 2744	C
 	mono-2.0-sgen.dll!ves_icall_System_Delegate_GetVirtualMethod_internal(_MonoDelegate * delegate) Line 6260	C
 	 (wrapper managed-to-native) System.Delegate:GetVirtualMethod_internal (System.Delegate) {004FE700} + 0x48 (03B915C0 03B91670) [00486668 - ConsoleApplication1.exe]	Unknown
 	[Frames below may be incorrect and/or missing]	
 	 System.Delegate:GetMethodImpl () {004ECF38} + 0xb8 (03B913B0 03B914A5) [00486668 - ConsoleApplication1.exe]	Unknown
 	 System.MulticastDelegate:GetMethodImpl () {004ED078} + 0x40 (03B91348 03B9139D) [00486668 - ConsoleApplication1.exe]	Unknown
 	 System.Delegate:get_Method () {004ED270} + 0x11 (03B91330 03B91343) [00486668 - ConsoleApplication1.exe]	Unknown
 	 Program:Main (string[]) {0048A500} + 0x70 (03B911D0 03B9124A) [00486668 - ConsoleApplication1.exe]	Unknown
 	 (wrapper runtime-invoke) <Module>:runtime_invoke_void_object (object,intptr,intptr,intptr) {004ECC50} + 0xa1 (03B91268 03B91330) [00486668 - ConsoleApplication1.exe]	Unknown
 	mono-2.0-sgen.dll!mono_jit_runtime_invoke(_MonoMethod * method, void * obj, void * * params, _MonoObject * * exc, _MonoError * error) Line 2616	C
 	mono-2.0-sgen.dll!do_runtime_invoke(_MonoMethod * method, void * obj, void * * params, _MonoObject * * exc, _MonoError * error) Line 2853	C
 	mono-2.0-sgen.dll!do_exec_main_checked(_MonoMethod * method, _MonoArray * args, _MonoError * error) Line 4682	C
 	mono-2.0-sgen.dll!mono_runtime_run_main_checked(_MonoMethod * method, int argc, char * * argv, _MonoError * error) Line 4223	C
 	mono-2.0-sgen.dll!mono_jit_exec(_MonoDomain * domain, _MonoAssembly * assembly, int argc, char * * argv) Line 1029	C
 	mono-2.0-sgen.dll!main_thread_handler(void * user_data) Line 1098	C
 	mono-2.0-sgen.dll!mono_main(int argc, char * * argv) Line 2169	C
Comment 1 Jonathan Chambers 2017-08-18 19:49:07 UTC
Proposed fix PR: https://github.com/mono/mono/pull/5404
Comment 2 Jonathan Chambers 2017-08-21 14:39:54 UTC
Fixed in master https://github.com/mono/mono/commit/1cfd52452a4af3fd6eee32f45a8067926af8479e