[MAJOR BUG] Entire server crash when Executing native "LOAD_RESOURCE_FILE" with null arg


#1

When I was making my script for FiveM. I kept running into this entire server crash that kept happening, at first I couldn’t think of the idea, then I started tweaking my code and found the direct source. Now, this bug only happens when you execute the fileName arg with null but still this shouldn’t crash the entire server, it should show up as an error in chat. I fixed the error in my code, but this type of error should be fixed because when the SIGSEGV linux error showed up, I couldn’t find the issue easily.

            static string fileName = null;

            // I forgot to call this before calling WriteLine(string line);
            public static void Create(string fileName)
            {
                Log.fileName = fileName;
            }

            public static void WriteLine(string line)
            {
                // Executing this code here when loading the "null" file crashed the server
                string data = Function.Call<string>(Hash.LOAD_RESOURCE_FILE, Function.Call<string>(Hash.GET_CURRENT_RESOURCE_NAME), fileName);
                string formatted = $"[{DateTime.Now}]: {line}";
                data = data + $"{formatted}\n";
                Function.Call(Hash.SAVE_RESOURCE_FILE, Function.Call<string>(Hash.GET_CURRENT_RESOURCE_NAME), fileName, data, -1);

                Debug.WriteLine(line);
            }

#2

On Windows this is actually handled properly, however on Linux one can’t catch native code exceptions across this type of boundary as there’s no native exception handling, this might actually be unfixable.