Opened 9 months ago

Last modified 9 months ago

#5587 new defect

Connection not established / Segfault after nick change and hosting STUN game

Reported by: elexis Owned by:
Priority: Should Have Milestone: Backlog
Component: Network Keywords:
Cc: Patch:

Description

In alpha 23 (at least my patched copy) and SVN I get a segfault for a client trying to join a STUN lobby game after the host nickname changed.

When the host cancels the game and clicks on host again, the progress dialog will remain stuck at the "Registering with server..." stage.

It seems there is some element of undefined behavior involved, because sometimes it sems to be fail in different ways (not even the host being able to join his game) depending on how many times one tries to host in a row.

0x00007ffff682def5 in gloox::Jingle::Session::sessionInitiate(gloox::Jingle::Content const*) () from /usr/lib/libgloox.so.17
(gdb) info stack
#0  0x00007ffff682def5 in gloox::Jingle::Session::sessionInitiate(gloox::Jingle::Content const*) () from /usr/lib/libgloox.so.17
#1  0x0000555555a2c8af in glooxwrapper::Jingle::Session::sessionInitiate (this=0x7fff00000000, ipStr=<optimized out>, port=<optimized out>) at ../../../source/lobby/glooxwrapper/glooxwrapper.cpp:850
#2  0x0000555555a1e533 in XmppClient::SendStunEndpointToHost (this=0x555556aca000, stunEndpoint=..., hostJIDStr=...) at ../../../source/lobby/XmppClient.cpp:1306
#3  0x0000555555a3cd35 in JSI_Network::StartNetworkJoin (pCxPrivate=0x555556af80f0, playerName=..., serverAddress=..., serverPort=20595, useSTUN=<optimized out>, hostJID=...)
    at ../../../source/network/scripting/JSInterface_Network.cpp:114
#4  0x0000555555a3e5aa in ScriptInterface_NativeWrapper<void>::call<void (ScriptInterface::CxPrivate*, CStrW const&, CStr8 const&, unsigned short, bool, CStr8 const&), CStrW, CStr8, unsigned short, bool, CStr8>(JSContext*, JS::MutableHandle<JS::Value>, void (ScriptInterface::CxPrivate*, CStrW const&, CStr8 const&, unsigned short, bool, CStr8 const&), CStrW, CStr8, unsigned short, bool, CStr8) (cx=<optimized out>, fptr=<optimized out>, params=..., params=..., 
    params=..., params=..., params=...) at ../../../source/scriptinterface/NativeWrapperDefns.h:85
#5  ScriptInterface::call<void, CStrW, CStr8, unsigned short, bool, CStr8, &JSI_Network::StartNetworkJoin> (cx=cx@entry=0x555556a94740, argc=<optimized out>, vp=0x555555d6df58) at ../../../source/scriptinterface/NativeWrapperDefns.h:124
#6  0x00007ffff7a239e8 in js::CallJSNative (args=..., native=0x555555a3e1b0 <ScriptInterface::call<void, CStrW, CStr8, unsigned short, bool, CStr8, &JSI_Network::StartNetworkJoin>(JSContext*, unsigned int, JS::Value*)>, 
    cx=0x555556a94740) at ../../dist/include/js/CallArgs.h:204
#7  js::Invoke (cx=0x555556a94740, args=..., construct=<optimized out>) at /home/elexis/code/0ad-svn/trunk/libraries/source/spidermonkey/mozjs-45.0.2/js/src/vm/Interpreter.cpp:444
#8  0x00007ffff7a194dc in Interpret (cx=0x555556a94740, state=warning: RTTI symbol not found for class 'gloox::Jingle::Content'
...) at /home/elexis/code/0ad-svn/trunk/libraries/source/spidermonkey/mozjs-45.0.2/js/src/vm/Interpreter.cpp:2766
#9  0x00007ffff7a23657 in js::RunScript (cx=cx@entry=0x555556a94740, state=...) at /home/elexis/code/0ad-svn/trunk/libraries/source/spidermonkey/mozjs-45.0.2/js/src/vm/Interpreter.cpp:391
#10 0x00007ffff7a2391d in js::Invoke (cx=cx@entry=0x555556a94740, args=..., construct=construct@entry=js::NO_CONSTRUCT) at /home/elexis/code/0ad-svn/trunk/libraries/source/spidermonkey/mozjs-45.0.2/js/src/vm/Interpreter.cpp:462
#11 0x00007ffff7a242fc in js::Invoke (cx=cx@entry=0x555556a94740, thisv=..., fval=..., argc=2, argv=<optimized out>, rval=..., rval@entry=...)
    at /home/elexis/code/0ad-svn/trunk/libraries/source/spidermonkey/mozjs-45.0.2/js/src/vm/Interpreter.cpp:496
#12 0x00007ffff7882ebd in JS_CallFunctionName (cx=0x555556a94740, obj=..., name=<optimized out>, args=..., rval=...) at ../../dist/include/js/Value.h:1667
#13 0x000055555570951f in ScriptInterface::CallFunction_ (this=0x555556af80f0, val=..., name=0x555555a807db "init", argv=..., ret=...) at ../../../source/scriptinterface/ScriptInterface.cpp:565
#14 0x000055555595bfd4 in ScriptInterface::CallFunctionVoid<JS::Rooted<JS::Value>, JS::Rooted<JS::Value> > (this=0x555556af80f0, val=..., name=0x555555a807db "init", params=..., params=...)
    at ../../../source/scriptinterface/NativeWrapperDefns.h:225
#15 0x0000555555958f45 in CGUIManager::SGUIPage::LoadPage (this=0x5555574a0360, scriptRuntime=...) at ../../../source/gui/GUIManager.cpp:213
#16 0x0000555555957f99 in CGUIManager::PushPage (this=0x555555e96c80, pageName=..., initData=warning: RTTI symbol not found for class 'std::_Sp_counted_ptr<ScriptInterface::StructuredClone*, (__gnu_cxx::_Lock_policy)2>'
warning: RTTI symbol not found for class 'std::_Sp_counted_ptr<ScriptInterface::StructuredClone*, (__gnu_cxx::_Lock_policy)2>'
std::shared_ptr<ScriptInterface::StructuredClone> (use count 2, weak count 0) = {...}, callbackFunction=...)
    at ../../../source/gui/GUIManager.cpp:104
#17 0x0000555555998525 in JSI_GUIManager::PushGuiPage (pCxPrivate=0x555558c692f0, name=..., initData=..., callbackFunction=...) at ../../../source/gui/scripting/JSInterface_GUIManager.cpp:32
#18 0x00005555559992c0 in ScriptInterface_NativeWrapper<void>::call<void (ScriptInterface::CxPrivate*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, JS::Handle<JS::Value>, JS::Handle<JS::Value>), std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, JS::Handle<JS::Value>, JS::Handle<JS::Value> >(JSContext*, JS::MutableHandle<JS::Value>, void (ScriptInterface::CxPrivate*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, JS::Handle<JS::Value>, JS::Handle<JS::Value>), std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, JS::Handle<JS::Value>, JS::Handle<JS::Value>) (cx=<optimized out>, fptr=<optimized out>, params=..., params=..., params=...) at ../../../source/scriptinterface/NativeWrapperDefns.h:85
#19 ScriptInterface::call<void, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, JS::Handle<JS::Value>, JS::Handle<JS::Value>, &JSI_GUIManager::PushGuiPage> (cx=cx@entry=0x555558b6fda0, 
    argc=<optimized out>, vp=0x555555d6ddf8) at ../../../source/scriptinterface/NativeWrapperDefns.h:124
#20 0x00007ffff7a239e8 in js::CallJSNative (args=..., 
    native=0x555555999110 <ScriptInterface::call<void, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, JS::Handle<JS::Value>, JS::Handle<JS::Value>, &JSI_GUIManager::PushGuiPage>(JSContext*, unsigned int, JS::Value*)>, cx=0x555558b6fda0) at ../../dist/include/js/CallArgs.h:204
#21 js::Invoke (cx=0x555558b6fda0, args=..., construct=<optimized out>) at /home/elexis/code/0ad-svn/trunk/libraries/source/spidermonkey/mozjs-45.0.2/js/src/vm/Interpreter.cpp:444
#22 0x00007ffff7a194dc in Interpret (cx=0x555558b6fda0, state=warning: RTTI symbol not found for class 'gloox::Jingle::Content'
...) at /home/elexis/code/0ad-svn/trunk/libraries/source/spidermonkey/mozjs-45.0.2/js/src/vm/Interpreter.cpp:2766
#23 0x00007ffff7a23657 in js::RunScript (cx=cx@entry=0x555558b6fda0, state=...) at /home/elexis/code/0ad-svn/trunk/libraries/source/spidermonkey/mozjs-45.0.2/js/src/vm/Interpreter.cpp:391
#24 0x00007ffff7a2391d in js::Invoke (cx=cx@entry=0x555558b6fda0, args=..., construct=construct@entry=js::NO_CONSTRUCT) at /home/elexis/code/0ad-svn/trunk/libraries/source/spidermonkey/mozjs-45.0.2/js/src/vm/Interpreter.cpp:462
#25 0x00007ffff7a242fc in js::Invoke (cx=0x555558b6fda0, thisv=..., fval=..., argc=1, argv=<optimized out>, rval=...) at /home/elexis/code/0ad-svn/trunk/libraries/source/spidermonkey/mozjs-45.0.2/js/src/vm/Interpreter.cpp:496
#26 0x00007ffff78824b9 in JS_CallFunctionValue (cx=<optimized out>, obj=..., fval=..., args=..., rval=...) at ../../dist/include/js/Value.h:1667
#27 0x000055555596dad0 in IGUIObject::ScriptEvent (this=0x555558f42f60, Action=...) at ../../../source/gui/IGUIObject.cpp:421
#28 0x000055555596c2a8 in IGUIObject::SendEvent (this=0x555558f42f60, type=<optimized out>, EventName=...) at ../../../source/gui/IGUIObject.cpp:391
#29 0x0000555555969c7f in IGUIButtonBehavior::HandleMessage (this=0x555558f42f20, Message=...) at ../../../source/gui/IGUIButtonBehavior.cpp:66
#30 0x00005555559807ed in virtual thunk to CButton::HandleMessage(SGUIMessage&) () at ../../../source/gui/CButton.cpp:75
#31 0x000055555596c29d in IGUIObject::SendEvent (this=0x555558f42f60, type=<optimized out>, EventName=...) at ../../../source/gui/IGUIObject.cpp:389
#32 0x0000555555925b2f in CGUI::HandleEvent (this=0x555558689880, ev=<optimized out>) at ../../../source/gui/CGUI.cpp:162
#33 0x000055555595694e in CGUIManager::HandleEvent (this=0x555555e96c80, ev=0x7fffffffe5e0) at ../../../source/gui/GUIManager.cpp:337
#34 0x0000555555956328 in gui_handler (ev=0x5555574b4670) at ../../../source/gui/GUIManager.cpp:48
#35 0x00005555559b1cc8 in in_dispatch_event (ev=0x7fffffffe5e0) at ../../../source/lib/input.cpp:62
#36 0x00005555555b1229 in PumpEvents () at ../../../source/main.cpp:227
#37 Frame () at ../../../source/main.cpp:367
#38 RunGameOrAtlas (argc=<optimized out>, argv=<optimized out>) at ../../../source/main.cpp:638
#39 0x00005555555aecd5 in main (argc=1, argv=0x7fffffffe8b8) at ../../../source/main.cpp:684

It was tried with nani and Angen today in both a23 and svn, and there the issue didn't occur. Or rather it didn't segfault, but the connection wasn't established either. Messagebox kept saying "Registering" with a "service unavailable" line in chat.

So from those experiments, it seems the segfault is only triggered when using two 0ad lobby accounts on the same computer, and otherwise the connection just doesn't work out.

Change History (1)

comment:1 Changed 9 months ago by elexis

I seem to get a crash when non-ASCI chars are used for hostJID.

For example on my modified but not in terms of STUN modified a23b copy plus this diff, I will get the segfault too.

diff --git a/binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.js b/binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.js
index 37de482b8e..3c7c297640 100644
--- a/binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.js
+++ b/binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.js
@@ -339,6 +339,7 @@ function startHost(playername, servername, port)
  */
 function startJoin(playername, ip, port, useSTUN, hostJID = "")
 {
+       hostJID = "ääää";
        try
        {
                Engine.StartNetworkJoin(playername + (g_UserRating ? " (" + g_UserRating + ")" : ""), ip, port, useSTUN, hostJID);

It sounds like the first STUN commit should have done an UTF8 coding call after receiving the string from the GUI, then passing the std::wstring or UTF8 encoded std::string around.

Bug was found while testing for Phab:D2271.

Notice that the current JS GUI enforces ASCII only characters, but I suppose the engine should support strings properly.

Note: See TracTickets for help on using tickets.