ASLRequst crashes
  • Cocoon
    Cocoon
    ciVic
    Posts: 45 from 2013/6/2
    Hi all,

    to keep it short, this crashes my app immediately after I close the request:

    app = ApplicationObject,End;
    fr = (struct FileRequester *)MUI_AllocAslRequest(ASL_FileRequest, frtags);
    MUI_AslRequest(fr, NULL);


    And this works:


    fr = (struct FileRequester *)MUI_AllocAslRequest(ASL_FileRequest, frtags);
    MUI_AslRequest(fr, NULL);
    app = ApplicationObject,End;


    This is only a short example. I have a fully running app where I'm not able to show a requester trying many examples. I also tried AllocAslRequest and AslRequest, same result.

    MorphOS 3.8 on PowerBook 5,9. Thx!
  • »14.06.15 - 18:36
    Profile
  • MorphOS Developer
    jacadcaps
    Posts: 2971 from 2003/3/5
    From: Canada
    It likely won't work if the application loop isn't running.
  • »14.06.15 - 19:41
    Profile Visit Website
  • Cocoon
    Cocoon
    ciVic
    Posts: 45 from 2013/6/2
    In fact its here:

    Code:

    while (running)
    {
    ULONG id = DoMethod((Object *)app,MUIM_Application_NewInput,&sigs);
    .
    .
    .
    case MEN_SWITCH_USER:
    fr = (struct FileRequester *)MUI_AllocAslRequest(ASL_FileRequest, frtags);
    if (fr != NULL)
    {
    if (MUI_AslRequest(fr, NULL))
    {
    }
    FreeAslRequest(fr);
    }
    else printf("User Cancelledn");
    break;
    }
    if (running && sigs) Wait(sigs);
    }


    It seems that a PopaslObject is a better choice. However, I don't see how to use it in a menu without buttons in the window. Any help?

    [ Editiert durch ciVic 14.06.2015 - 21:29 ]
  • »14.06.15 - 21:56
    Profile
  • MorphOS Developer
    itix
    Posts: 1516 from 2003/2/24
    From: Finland
    Quote:

    ciVic wrote:
    Hi all,

    to keep it short, this crashes my app immediately after I close the request:

    app = ApplicationObject,End;
    fr = (struct FileRequester *)MUI_AllocAslRequest(ASL_FileRequest, frtags);
    MUI_AslRequest(fr, NULL);


    And this works:


    fr = (struct FileRequester *)MUI_AllocAslRequest(ASL_FileRequest, frtags);
    MUI_AslRequest(fr, NULL);
    app = ApplicationObject,End;


    This is only a short example. I have a fully running app where I'm not able to show a requester trying many examples. I also tried AllocAslRequest and AslRequest, same result.

    MorphOS 3.8 on PowerBook 5,9. Thx!


    Uhm, I am certain it works. See here:

    Quote:


    int SaveWindowBuffer(const char *filename)
    {
    int retval;

    if (filename)
    {
    retval = SaveBuffer(filename);
    }
    else
    {
    struct FileRequester *req;
    static struct TagItem tags[] =
    {
    { ASLFR_TitleText , 0 },
    { ASLFR_DoPatterns , TRUE },
    { ASLFR_DoSaveMode , TRUE },
    { ASLFR_InitialDrawer , (IPTR)(CONST_STRPTR)"RAM:" },
    { ASLFR_InitialFile , (IPTR)(CONST_STRPTR)"Snoopium.log" },
    { ASLFR_InitialPattern, (IPTR)(CONST_STRPTR)"#?.log" },
    { TAG_DONE, 0 }
    };

    req = SaveLogReq;

    if (!req)
    {
    tags[0].ti_Data = (ULONG)MSG(MSG_ASL_SAVEBUFFER);
    SaveLogReq = req = (struct FileRequester *)MUI_AllocAslRequest(ASL_FileRequest, (struct TagItem *)tags);
    }

    retval = 0;

    if (req)
    {
    if (MUI_AslRequest(req, NULL))
    {
    BPTR lock;

    lock = Lock(req->rf_Dir, ACCESS_READ);

    filename = req->rf_File;

    if (lock)
    {
    lock = CurrentDir(lock);
    retval = SaveBuffer(filename);

    UnLock(CurrentDir(lock));
    }
    }
    }
    }

    if (!retval && filename)
    ShowError(MSG(MSG_ERROR_SAVING_BUFFER), (ULONG)filename);

    return retval;
    }



    http://snoopium.cvs.sourceforge.net/viewvc/snoopium/Snoopium/mainwin.c?revision=1.30&view=markup
    1 + 1 = 3 with very large values of 1
  • »14.06.15 - 22:43
    Profile
  • Cocoon
    Cocoon
    ciVic
    Posts: 45 from 2013/6/2
    I tried this source, also no solution. Maybe I should mention that I use gcc 4.4.5 as it seems that it sometimes is a problem, that is why I need SDI_HOOK.h. I've found a ppcinline/muimaster.h that defines the MUI_ASLRequest differently, but it is not used.
  • »15.06.15 - 21:02
    Profile
  • MorphOS Developer
    itix
    Posts: 1516 from 2003/2/24
    From: Finland
    SDI_HOOK.h? I would throw that away and use something native.

    I dont think GCC 4.4.5 would matter but compiler bugs are always possible.
    1 + 1 = 3 with very large values of 1
  • »15.06.15 - 23:16
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    pegasos-sigi2
    Posts: 265 from 2006/8/31
    Quote:

    ciVic wrote:
    I tried this source, also no solution. Maybe I should mention that I use gcc 4.4.5 as it seems that it sometimes is a problem, that is why I need SDI_HOOK.h. I've found a ppcinline/muimaster.h that defines the MUI_ASLRequest differently, but it is not used.


    This code works for me. And this code did't need a mui gui, so it can open a asl requester
    in a shell prog.

    Code:
    int asl (char kopf[],BOOL save,STRPTR pattern,char dir_[150],char *out,char *_dir,char *_file, char ifile[])
    {
    struct FileRequester *fr;
    unsigned char file[100] = "";
    unsigned char dir[100] = "";
    unsigned char path[100]= "";
    int filezahl = 0;

    AslBase = OpenLibrary("asl.library",40L);
    if (AslBase != NULL)
    {
    if( (fr = AllocAslRequestTags( ASL_FileRequest,
    ASL_Hail, (ULONG) kopf,
    ASL_OKText, (ULONG) "OK",
    ASL_CancelText, (ULONG) "Cancel",
    ASL_File, (ULONG) ifile,
    ASL_Dir, (ULONG) dir_,

    ASLFR_DoSaveMode,save,
    ASLFR_DoPatterns,TRUE,
    ASLFR_InitialPattern,pattern,
    TAG_DONE ) ) )
    {
    if (AslRequest(fr, NULL))
    {
    strcpy(file,fr->rf_File);
    strcpy(dir,fr->rf_Dir);
    strcpy(_dir,dir);
    strcpy(_file,file);


    strcat(path,dir);
    strcat(path,"/");
    strcat(path,file);
    strcpy(out,path);

    if (strstr(path,":/") != 0)
    {
    unsigned char path[100] = "";
    strcat(path,dir);
    strcat(path,file);
    strcpy(out,path);
    }
    }
    else
    {
    if (IoErr())
    {
    /*Es wird 0 in path2 kopiert, wenn man den Close-Button oder "Cancel" betätigt.*/
    strcpy(out,"0");
    return 0;
    }
    else
    {
    /*Es wird 0 in path2 kopiert, wenn man den Close-Button oder "Cancel" betätigt.*/
    strcpy(out,"0");
    return 0;
    }
    }
    FreeAslRequest(fr);
    }
    else
    {
    /* Es wird -1 in path2 kopiert, wenn man nicht die asl.library öffnen kann.*/
    strcpy(out,"-1");
    return -1;
    }
    CloseLibrary(AslBase);
    }
    return 1;
    }


    Spreedy - The spreedsheet editor of MorphOS
    Calimero - Do you know about the new DTP Program for MorphOS ?
  • »16.06.15 - 10:27
    Profile
  • MorphOS Developer
    geit
    Posts: 1031 from 2004/9/23
    Actually your example has several issues.

    First of all: I now know how to crash all your applications as you limit the name/dir/path to 100 without any proper checking. Even if you increase the path to 1000 it is a no go without proper error checking. And even with error checking you limit the user to a path of 100, which is nothing.

    Check the size of the name and path fields delivered by ASL and allocate memory with the proper size and copy the data in. Avoid fixed sized buffers if possible or at least check boundaries.

    In addition to that you are dealing with "/" on your own. There are functions for that in AmigaDOS. You assume a path is delivered without a slash, but what if the user edits the field by hand or ASL gets modified to return a slash? In that case with your code you get "path:drawer//file", which is wrong.

    Seriously use AddPart().

    And avoid using of blah[<number>] in code. It screams for protential errors. Use proper constants you define at one place. Numbers in code are bad and will cause trouble in the future.

    use:

    #define FILEBUFFER_SIZEOF 0x100

    char file[ FILEBUFFER_SIZEOF ];

    this way you have the proper name for checking the buffer size without using 100 as length in strncpy(() or strncat().
  • »16.06.15 - 12:29
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    pegasos-sigi2
    Posts: 265 from 2006/8/31
    You did't know, thats impossible to iclude manuel a "/" in the asl requester.
    After a you push the return button the "/" disapear.
    A user can manuel change the text in the asl requester, but no adding the "/".
    Test it!
    I can't get such thing like ""path:drawer//file"".



    Quote:

    geit wrote:
    Actually your example has several issues.

    First of all: I now know how to crash all your applications as you limit the name/dir/path to 100 without any proper checking. Even if you increase the path to 1000 it is a no go without proper error checking. And even with error checking you limit the user to a path of 100, which is nothing.

    Check the size of the name and path fields delivered by ASL and allocate memory with the proper size and copy the data in. Avoid fixed sized buffers if possible or at least check boundaries.

    In addition to that you are dealing with "/" on your own. There are functions for that in AmigaDOS. You assume a path is delivered without a slash, but what if the user edits the field by hand or ASL gets modified to return a slash? In that case with your code you get "path:drawer//file", which is wrong.

    Seriously use AddPart().

    And avoid using of blah[<number>] in code. It screams for protential errors. Use proper constants you define at one place. Numbers in code are bad and will cause trouble in the future.

    use:

    #define FILEBUFFER_SIZEOF 0x100

    char file[ FILEBUFFER_SIZEOF ];

    this way you have the proper name for checking the buffer size without using 100 as length in strncpy(() or strncat().
    Spreedy - The spreedsheet editor of MorphOS
    Calimero - Do you know about the new DTP Program for MorphOS ?
  • »16.06.15 - 22:52
    Profile
  • MorphOS Developer
    geit
    Posts: 1031 from 2004/9/23
    Quote:

    pegasos-sigi2 wrote:
    You did't know, thats impossible to iclude manuel a "/" in the asl requester.
    After a you push the return button the "/" disapear.
    A user can manuel change the text in the asl requester, but no adding the "/".
    Test it!
    I can't get such thing like ""path:drawer//file"".




    Thats not the point. You assume this will work that way. Using the same code on OS3.x may not work. What if someone patched to ReqTools there.

    Do not compose paths on your own. This at some point will fail very badly.

    System functions are there to be used. It even makes your code more save and the code size get smaller when using DOS functions like AddPart() and FilePart().

    And do not use fixed size file name buffers. This will fail very easy.


    [ Edited by geit 17.06.2015 - 01:34 ]
  • »17.06.15 - 01:33
    Profile
  • Cocoon
    Cocoon
    ciVic
    Posts: 45 from 2013/6/2
    Ok I've got a short source code that all should be able to compile and to crash:

    Code:

    /* Compile: gcc Crash.c */
    #include <proto/intuition.h>
    #include <proto/asl.h>
    #include <proto/muimaster.h>
    struct Library *MUIMasterBase, *AslBase;
    struct IntuitionBase *IntuitionBase;
    int main(int argc,char *argv[]) {
    APTR fr;
    MUIMasterBase = OpenLibrary("muimaster.library",0);
    AslBase = OpenLibrary("asl.library", 0);
    IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",39);
    ApplicationObject,End;
    fr = (struct FileRequester *)MUI_AllocAslRequestTags(ASL_FileRequest, TAG_DONE);
    MUI_AslRequest(fr, NULL); }


    If you comment out ApplicationObject... it works, if you compile without ixemul it works. But not this way.
  • »20.06.15 - 13:00
    Profile
  • MorphOS Developer
    Piru
    Posts: 576 from 2003/2/24
    From: finland, the l...
    Quote:

    without ixemul it works

    Ixemul is meant for building bsd/linux apps. You should not mix ixemul and MorphOS OS functions.
  • »20.06.15 - 16:05
    Profile
  • Cocoon
    Cocoon
    ciVic
    Posts: 45 from 2013/6/2
    Need curl, ssl, etc and in contrast to AmigaOS there is no curl without.

    [ Editiert durch ciVic 20.06.2015 - 15:19 ]
  • »20.06.15 - 16:18
    Profile
  • MorphOS Developer
    Piru
    Posts: 576 from 2003/2/24
    From: finland, the l...
    Quote:

    Need curl, ssl, etc

    curl and openssl can be built for libnix. It requires some effort though.

    Fab has offered to provide libnix curl if needed.
  • »20.06.15 - 16:48
    Profile
  • Cocoon
    Cocoon
    ciVic
    Posts: 45 from 2013/6/2
    Ah ok, thx! That would be an option. I forgot that old thread.

    [ Editiert durch ciVic 20.06.2015 - 16:01 ]
  • »20.06.15 - 17:00
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    pegasos-sigi2
    Posts: 265 from 2006/8/31
    Quote:

    ciVic wrote:
    Ah ok, thx! That would be an option. I forgot that old thread.

    [ Editiert durch ciVic 20.06.2015 - 16:01 ]


    I have the libcurl. Do you need it ?
    Spreedy - The spreedsheet editor of MorphOS
    Calimero - Do you know about the new DTP Program for MorphOS ?
  • »20.06.15 - 21:45
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    pegasos-sigi2
    Posts: 265 from 2006/8/31
    Quote:

    ciVic wrote:
    Ah ok, thx! That would be an option. I forgot that old thread.

    [ Editiert durch ciVic 20.06.2015 - 16:01 ]


    I have the libcurl dou you need it?
    Spreedy - The spreedsheet editor of MorphOS
    Calimero - Do you know about the new DTP Program for MorphOS ?
  • »20.06.15 - 21:45
    Profile
  • Cocoon
    Cocoon
    ciVic
    Posts: 45 from 2013/6/2
    Quote:

    pegasos-sigi2 schrieb:
    Quote:

    ciVic wrote:
    Ah ok, thx! That would be an option. I forgot that old thread.

    [ Editiert durch ciVic 20.06.2015 - 16:01 ]


    I have the libcurl dou you need it?


    Yes, please! :-)
  • »21.06.15 - 10:48
    Profile