Menu

#708 Script console - app crash instead display error

Undefined
open
nobody
None
Bug_Report
2018-07-26
2018-07-05
ololuki
No

Problem exists in Code::Blocks 17.12 and nightly 11400 on Windows and Code::Blocks 16.01 on Debian.

Any project (.cbp) must be opened in Code::Blocks.
Typing following command in scripting console causes crash of Code::Blocks:
GetProjectManager().GetActiveProject().SetCommandsBeforeBuild(T("cmd /c mkdir abc"));

SetCommandsBeforeBuild takes const wxArrayString&, but in this command it gets const wxString&
Maybe there should be some type checking?

1 Attachments

Discussion

  • ololuki

    ololuki - 2018-07-05

    There should be underscore before T():

    GetProjectManager().GetActiveProject().SetCommandsBeforeBuild(_T("cmd /c mkdir abc"));
    
     
  • bluehazzard

    bluehazzard - 2018-07-17

    as far as i can tell, type checking for instances is hard with the current squirrel binding...
    [EDIT:] THIS IS WRONG. sqplus implements type checking for instances. I check why this is not triggered here...

    One possibility to clean this up would be to add a constructor for string for the wxStringArray type...

     

    Last edit: bluehazzard 2018-07-17
  • bluehazzard

    bluehazzard - 2018-07-17

    But we should somehow prevent a fatal crash as it is happening at the moment...

     
  • bluehazzard

    bluehazzard - 2018-07-17

    Ok, i found the problem:
    in include\scripting\sqplus\sqplus.h:539 the instance is get from the squirrel vm and type checking is done:

    template<typename T,bool ExceptionOnError>
    T * GetInstance(HSQUIRRELVM v,SQInteger idx) {
      SQUserPointer up=0;
      sq_getinstanceup(v,idx,&up,ClassType<T>::type());
      if (ExceptionOnError) { // This code block should be compiled out when ExceptionOnError is false. In any case, the compiler should not generate a test condition (include or exclude the enclosed code block).
        if (!up) throw SquirrelError(sqT("GetInstance: Invalid argument type"));
      } // if
      return (T *)up;
    } // GetInstance
    

    in

    sq_getinstanceup(v,idx,&up,ClassType<T>::type());
    

    the type is checked:

    SQRESULT sq_getinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag)
    {
        SQObjectPtr &o = stack_get(v,idx);
        if(type(o) != OT_INSTANCE) return sq_throwerror(v,_SC("the object is not a class instance"));
        (*p) = _instance(o)->_userpointer;
        if(typetag != 0) {
            SQClass *cl = _instance(o)->_class;
            do{
                if(cl->_typetag == typetag)
                    return SQ_OK;
                cl = cl->_base;
            }while(cl != NULL);
            return sq_throwerror(v,_SC("invalid type tag"));
        }
        return SQ_OK;
    }
    

    and if it is false a

    sq_throwerror(v,_SC("invalid type tag"));
    

    is raised and a not SQ_OK is returned. 'GetInstance' does not check the return type but the user pointer for null. This is wrong and will never fail...

     

    Last edit: bluehazzard 2018-07-18
  • bluehazzard

    bluehazzard - 2018-07-17

    Found some discussion in the squirrel forum:
    http://www.squirrel-lang.org/mainsite/forums/default.aspx?g=posts&m=2949

    I have tried to fix it with the suggested version in the forum (i have not found the commit in sqplus yet) and it does not work for plugins like the scripted wizard.

    The cl->_typetag and the typetag for the application and the plugin are different pointer to the same type....

    _typetag = 0x694148c8 <SqPlus::ClassType<wxString>::copy(wxString*, wxString*)>
    
    output typetag
    [debug](SQUserPointer) 0x66ba9f30 <SqPlus::ClassType<wxString>::copy(wxString*, wxString*)
    
     
  • bluehazzard

    bluehazzard - 2018-07-18

    Ok, there are two ways to fix this:
    1) update sqplus to the latest version: I think without future patching sqplus this will not work, because in the latest version they use the same pointer to static member as in the last versions, but they fixed the type checking...
    2) Use the attached patch that should fix all problems... I have used typeid for type identification and fixed the GetInstance()function...

     

    Last edit: bluehazzard 2018-07-18
  • bluehazzard

    bluehazzard - 2018-07-19

    Ok, i tried to update sqplus to the latest version and it would be a lot work to fix the bug with the static class identification, so i will put this aside....

     
  • Teodor Petrov

    Teodor Petrov - 2018-07-20

    We should move to your sq3+sqrat branch. But it requires many changes and experiments how to make handling of errors correctly. The current version didn't work well if I remember correctly.

     
  • bluehazzard

    bluehazzard - 2018-07-20

    I agree, but this patch prevents some serious crashes in the meantime...

     
  • Teodor Petrov

    Teodor Petrov - 2018-07-25

    It requires working RTTI, this is not really the case on linux when loading plugins with dlopen. Not sure if it affects the scripting engine, but I prefer if we don't find out late.

     
  • bluehazzard

    bluehazzard - 2018-07-26

    As far as i can tell my fix works on windows and linux (at least mint 18) and gcc (other compiler probably won't work, but we use gcc everywhere...)

     

    Last edit: bluehazzard 2018-07-26

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.