Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Cuberite crashes under Windows 11 when player functions are called #5594

Open
Seadragon91 opened this issue Dec 6, 2024 · 3 comments
Open

Comments

@Seadragon91
Copy link
Contributor

Client version: 1.12.2
Server OS: Windows 11
Cuberite Commit id: 4b2b02a

Expected behavior

A bad API call should not crash the server.

Actual behavior

Server crashes when this function is called:
a_Player:SendMessageFailure(true)

Steps to reproduce the behavior

Run this plugin:

function Initialize(a_Plugin)
        g_Plugin = a_Plugin
        a_Plugin:SetName("TestPlugin")
        a_Plugin:SetVersion(1)

        cPluginManager.BindCommand("/testit", "", CmdTestIt, " - testit")
        return true
end

function CmdTestIt(a_Split, a_Player)
        a_Player:SendMessageFailure(true)
        a_Player:SendMessage("Command run")
        return true
end

Server log

[20:43:18] Player Seadragon91 is executing command "/testit" in world "world" at world age 1149.
[20:43:18] LUA: Plugins\TestPlugin/TestPlugin.lua:11: error in function 'SendMessageFailure'.
     argument #2 is 'boolean'; 'string' expected.

[20:43:18] Stack trace:
[20:43:18]   [C](-1): SendMessageFailure
[20:43:18]   Plugins\TestPlugin/TestPlugin.lua(11): (no name)
[20:43:18] Stack trace end

Hello long time no see :)

Started testing my Plugin APIFuzzing and got many crashes.
I think the cause for most of them is the same.
Bisected the cause down to this commit: 7b8f6eb

When I run the plugin under Linux, no crash occurs I only see the output above.
Under windows after the output the server crashes.
Not sure if that is a problem only under windows 11. I don't have windows 10 anymore.

@bearbin
Copy link
Member

bearbin commented Dec 6, 2024

Long time no see!

What a strange issue. Can you attach a debugger and identify the actual cause of the crash? I guess we must not be handling the lua error in some way, but it's strange that the behaviour differs depending on system.

@Seadragon91
Copy link
Contributor Author

Seadragon91 commented Dec 7, 2024

Sadly the stacktrace doesn't point to any line in the code, but I see lua5.1 in the output.
When I run the server under debug, no crash occurs and I see this in the console:

LOGD("LUA: BreakIntoDebugger() not found / not a function");

Edit: Added debug infos to release mode and now I see where the crash occurs. This is from the generated file Bindings.cpp:

/* method: SendMessageFailure of class  cPlayer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_SendMessageFailure00
static int tolua_AllToLua_cPlayer_SendMessageFailure00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
     !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,3,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  cPlayer* self = (cPlayer*)  tolua_tousertype(tolua_S,1,nullptr);
  const AString a_Message = ((const AString)  tolua_tocppstring(tolua_S,2,nullptr));
#ifndef TOLUA_RELEASE
  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SendMessageFailure'", nullptr);
#endif
  {
   self->SendMessageFailure(a_Message);
  }
 }
 return 0;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'SendMessageFailure'.",&tolua_err);
 return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

This check fails: !tolua_iscppstring(tolua_S,2,0,&tolua_err) as is pass a boolean instead of a string, this calls then tolua_error(tolua_S,"#ferror in function 'SendMessageFailure'.",&tolua_err); and crashes the server.
Maybe some paramater for Bindings are wrong.

@Seadragon91
Copy link
Contributor Author

Reverting tolua++ to commit 26e85c4 fixes the crash, not sure what there is wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants