dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.42k stars 4.76k forks source link

mono code line crash my server #110006

Closed aotto1968 closed 1 day ago

aotto1968 commented 2 days ago

Description

Hi, the following line of code crash my server:

GetType().GetMethod("ReadI").Invoke(this,null);

The Method-Name ReadI is wrong and I expect to get a NULL pointer exception but mono crash:

short

Bug is method.Invoke(this,null) with an invalid (null?) method -> expect: System.NullReferenceException -> get: CORE -> last GOOD command is Console.WriteLine("method=" + method); -> search for method= in attachment

####################################################################################################

BAD code (core)

    # HIGH is a delegate called as "service"
    private void HIGH () {
      var s = ReadSTR() ;
      switch (s) {
        case "SEND_ONE_BUF": {
          var t = ReadSTR();
          //var tt = ReadSTR();
Console.WriteLine("START");
          var type = GetType();
Console.WriteLine("type=" + type);
          var method = type.GetMethod($"Read{t}");  // calling: "ReadI"
Console.WriteLine("method=" + method);
          var read = method.Invoke(this,null);      // !! CORE !!
Console.WriteLine(read);
          var ret = (MkBufferC) Send("W",$"ECOA:{t}@U",read);
          //var ret = (MkBufferC) Send("W",$"ECOA:{t}@U",GetType().GetMethod($"Read{tt}").Invoke(this,null));
          Send("R","U",ret);
          break;
        }
      ...
    }

attachment: trace until crash -> bug_crash.log

####################################################################################################

GOOD code (reference)

using System;

sealed class BugGetMethodCore {
  Object make_core() {
    var type = GetType();
Console.WriteLine("type=" + type);
    var method = type.GetMethod("ReadI");
Console.WriteLine("method=" + method);
    var read = method.Invoke(this,null);
Console.WriteLine(read);
    return read;
  }

  static void Main(string[] argv) {
    var bug = new BugGetMethodCore();
    Console.WriteLine(bug.make_core());
  }
} 

test code → OK

attachment: trace until end -> bug_good.log The message from MqDisasterSignal is my crash handler listen on SIGSEGV

void MqDisasterSetup(void) {
  // once per application
  static bool setup_done = false;
  if (setup_done) return;
  setup_done = true;

  // initialised to all zero (I vote for GCC style breach of standard here)
  struct sigaction sa = {};

  sa.sa_handler = MqDisasterSignal;
  sa.sa_flags = 0 /* | SA_RESETHAND | SA_NODEFER */;  /* To have or have not */
//  sigaction(SIGINT, &MqDisasterSA, NULL);
  sigaction(SIGSEGV, &sa, NULL);
}

GOOD error message from reference code

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at BugGetMethodCore.make_core () [0x00034] in <0ad1f995e5b047fe81582953d312d059>:0
  at BugGetMethodCore.Main (System.String[] argv) [0x00007] in <0ad1f995e5b047fe81582953d312d059>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at BugGetMethodCore.make_core () [0x00034] in <0ad1f995e5b047fe81582953d312d059>:0
  at BugGetMethodCore.Main (System.String[] argv) [0x00007] in <0ad1f995e5b047fe81582953d312d059>:0

Reproduction Steps

have reference example but CORE only happen in my server code.

Expected behavior

expect: System.NullReferenceException

Actual behavior

get: core

Regression?

No response

Known Workarounds

No response

Configuration

uname -a Linux linux02 5.14.21-150500.55.83-default #1 SMP PREEMPT_DYNAMIC Wed Oct 2 08:09:07 UTC 2024 (0d53847) x86_64 x86_64 x86_64 GNU/Linux cat /etc/SUSE-brand openSUSE VERSION = 15.5 mono -V Mono JIT compiler version 6.8.0.105 (tarball Fri Jun 23 18:47:43 UTC 2023) Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com TLS: __thread SIGSEGV: altstack Notifications: epoll Architecture: amd64 Disabled: none Misc: softdebug Interpreter: yes LLVM: supported, not enabled. Suspend: hybrid GC: sgen (concurrent by default)

Other information

No response

huoyaoyuan commented 2 days ago

mono -V Mono JIT compiler version 6.8.0.105 (tarball Fri Jun 23 18:47:43 UTC 2023)

This is the old, .NET Framework-compatible Mono at https://github.com/mono/mono . It's now sunsetting. If you don't need .NET Framework compatibility, you can move to modern .NET on Linux.

aotto1968 commented 2 days ago

Image

this is the mono OpenSUSE offering I can use → what should I choose?

I found a link on MS website: https://learn.microsoft.com/en-us/dotnet/core/install/linux-opensuse is this the official C# on linux?

huoyaoyuan commented 2 days ago

I found a link on MS website: https://learn.microsoft.com/en-us/dotnet/core/install/linux-opensuse is this the official C# on linux?

Yes. For modern .NET, there are binaries built by Microsoft, and by distro owners. Both are considered official, supported by whoever builds them. This repo is the upstream and patches will be adopted by distro owners. dotnet is the common moniker for package names.

aotto1968 commented 2 days ago

I download an install this, but this is an complete other architecture… this mean I have to rewrite my own build-process… this is now an unplanned task and will be moved into the near future.

huoyaoyuan commented 2 days ago

but this is an complete other architecture… this mean I have to rewrite my own build-process…

Unfortunately yes, it's a migration. The effort for maintaining old mono is very low now so it's unlikely to get the bug fixed in time.

jkotas commented 1 day ago

The old mono is maintained at https://gitlab.winehq.org/mono/mono . You can report the issue there.

Closing - this issue is not actionable in this repo.