R2Northstar / NorthstarMods

Squirrel scripts used to recreate server-side gamelogic and add custom content to the game.
MIT License
153 stars 122 forks source link

Server crash at startup if mod.json has a ConVar with a non-string DefaultValue #409

Closed fvnkhead closed 2 years ago

fvnkhead commented 2 years ago

Try with any mod that has a bool value (eg.: "1" or "0") in convars, and remove the quotes around it.

Example: this works fine...

        {
            "Name": "fm_welcome_enabled",
            "DefaultValue": "1"
        },

...but if I do this...

        {
            "Name": "fm_welcome_enabled",
            "DefaultValue": 1
        },

...I get this:

[11:54:45] [error] Northstar has crashed! a minidump has been written and exception info is available below:
[11:54:45] [error] Cause: Access Violation
Attempted to read from: 0x0000000000000000
[11:54:45] [error] At: Northstar.dll + 0x65f23
[11:54:45] [error]     Northstar.dll + 0x52343 (0x16912343)
[11:54:45] [error]     ntdll.dll + 0x25753 (0x170025753)
[11:54:45] [error]     ntdll.dll + 0x548c5 (0x1700548c5)
[11:54:45] [error]     ntdll.dll + 0x5245e (0x17005245e)
[11:54:45] [error]     Northstar.dll + 0x65f23 (0x16925f23)
[11:54:45] [error]     Northstar.dll + 0x6776d (0x1692776d)
[11:54:45] [error]     Northstar.dll + 0x671e9 (0x169271e9)
[11:54:45] [error]     Northstar.dll + 0x6c282 (0x1692c282)
[11:54:45] [error]     Northstar.dll + 0x48727 (0x16908727)
[11:54:45] [error]     Northstar.dll + 0x489a9 (0x169089a9)
[11:54:45] [error]     filesystem_stdio.dll + 0x3d74a (0x18bed74a)
[11:54:45] [error]     filesystem_stdio.dll + 0x3d8e1 (0x18bed8e1)
[11:54:45] [error]     filesystem_stdio.dll + 0x15468 (0x18bc5468)
[11:54:45] [error]     launcher.dll + 0x14d69 (0x16b44d69)
[11:54:45] [error]     launcher.dll + 0x12b0b (0x16b42b0b)
[11:54:45] [error]     launcher.dll + 0x9626 (0x16b39626)
[11:54:45] [error]     launcher.dll + 0x151b9 (0x16b451b9)
[11:54:45] [error]     launcher.dll + 0x15ae9 (0x16b45ae9)
[11:54:45] [error]     launcher.dll + 0x15afd (0x16b45afd)
[11:54:45] [error]     launcher.dll + 0xd386 (0x16b3d386)
[11:54:45] [error]     NorthstarLauncher.exe + 0x45e0 (0x1400045e0)
[11:54:45] [error]     NorthstarLauncher.exe + 0x7900 (0x140007900)
[11:54:45] [error]     kernel32.dll + 0x2c599 (0x7b62c599)
[11:54:45] [error]     ntdll.dll + 0x59d53 (0x170059d53)
[11:54:45] [error]     NorthstarLauncher.exe + 0xfffffffec0000000 (0x0)
[11:54:45] [error]     NorthstarLauncher.exe + 0x7970 (0x140007970)
[11:54:45] [error]     NorthstarLauncher.exe + 0x67ff0000 (0x67ff0000)
[11:54:45] [error]     NorthstarLauncher.exe + 0xfffffffec0000000 (0x0)
[11:54:45] [error] RAX: 0x0
[11:54:45] [error] RBX: 0x6cd0460
[11:54:45] [error] RCX: 0x6cd0480
[11:54:45] [error] RDX: 0x54b0050
[11:54:45] [error] RSI: 0x169d7078
[11:54:45] [error] RDI: 0x54b0500
[11:54:45] [error] RBP: 0x7cbeb0
[11:54:45] [error] RSP: 0x7cbdb0
[11:54:45] [error] R8: 0x0
[11:54:45] [error] R9: 0x65
[11:54:45] [error] R10: 0x6cd6f10
[11:54:45] [error] R11: 0x8e0000
[11:54:45] [error] R12: 0x7cdec0
[11:54:45] [error] R13: 0x0
[11:54:45] [error] R14: 0x169d7090
[11:54:45] [error] R15: 0x54b05d0
0024:fixme:dbghelp_dwarf:dwarf2_read_range no entry found
0024:fixme:dbghelp_dwarf:dwarf2_read_range no entry found
0024:fixme:dbghelp:MiniDumpWriteDump NIY MiniDumpScanMemory

Took me a while to debug

Alystrasz commented 2 years ago

I don't know if this behavior is intended or not; anyway, it will be mentioned in the modding docs: https://github.com/R2Northstar/ModdingDocs/pull/39

F1F7Y commented 2 years ago

From a Squirrel perspective a convar doesn't have a type. You can call GetConVarString and GetConVarInt on the same convar. I can't speak for how Launcher could / should handle an edge case like this

uniboi commented 2 years ago

Isn't this intended behaviour? Either way I don't think this should be changed

F1F7Y commented 2 years ago

A ConVar not having a type is intended behaviour, this crash isn't and should be addressed even if it's very miniscule

emma-miler commented 2 years ago

I don't have access to an environment to test this at the moment, but i highly suspect the bug is actually not with the mods repo. As you can see here we call GetString on the JSON object directly. Assuming that convarObj is of type rapidjson::GenericValue, that method looks like this:

const Ch* GetString() const { RAPIDJSON_ASSERT(IsString()); return DataString(data_); }

source For any non-string value, the assert will fail and an error will be generated. This will then crash the program. We should either do some error-checking here or use a different method. In either case, I will open a new issue on the launcher about this issue. @GeckoEidechse or @fvnkhead, could you close this issue.