Page 1 of 1

wxFTP::PWD() error

Posted: Thu Sep 22, 2016 8:16 pm
by Oleg
I am going to use wxFTP to connect to ftp server and get current working directory with this code:

Code: Select all

   wxFTP ftp;
   ftp.SetUser(wxT("username"));
   ftp.SetPassword(wxT("password"));

   if (ftp.Connect("ipaddres"))
   {
      std::cout << "Connected" << std::endl;
      wxString str = ftp.Pwd(); <<------- ERROR: string iterator not dereferencable
   }


But when i use

Code: Select all

ftp.Pwd()
i have error (see screenshot). What am i doing wrong?
error.png
error.png (12.36 KiB) Viewed 2139 times

Re: wxFTP::PWD() error

Posted: Thu Sep 22, 2016 8:38 pm
by Oleg
Error occurred at:

Code: Select all

wxString wxFTP::Pwd()
{
    wxString path;

    if ( CheckCommand(wxT("PWD"), '2') )
    {
        // the result is at least that long if CheckCommand() succeeded
        wxString::const_iterator p = m_lastResult.begin() + LEN_CODE + 1;
        if ( *p != wxT('"') )
        {
            wxLogDebug(wxT("Missing starting quote in reply for PWD: %s"),
                       wxString(p, m_lastResult.end()));
        }
        else
        {
            for ( ++p; *p; ++p )
            {
                if ( *p == wxT('"') )
                {
                    // check if the quote is doubled
                    ++p;
                    if ( !*p || *p != wxT('"') ) <<----------- ERROR: string iterator not dereferencable WTF???
                    {
                        // no, this is the end
                        break;
                    }
                    //else: yes, it is: this is an embedded quote in the
                    //      filename, treat as normal char
                }

                path += *p;
            }

            if ( !*p )
            {
                wxLogDebug(wxT("Missing ending quote in reply for PWD: %s"),
                           m_lastResult.c_str() + LEN_CODE + 1);
            }
        }
    }
    else
    {
        m_lastError = wxPROTO_PROTERR;
        wxLogDebug(wxT("FTP PWD command failed."));
    }

    return path;
}

Re: wxFTP::PWD() error

Posted: Thu Sep 22, 2016 11:03 pm
by doublemax
If you break into the debugger, what does "m_lastResult" contain?

Re: wxFTP::PWD() error

Posted: Fri Sep 23, 2016 8:06 am
by Oleg
@doublemax that is what i have:
last error.png
last error.png (34.1 KiB) Viewed 2111 times

Re: wxFTP::PWD() error

Posted: Fri Sep 23, 2016 9:42 am
by doublemax
What does "p" point to at the moment of the crash?

It looks that the ftp server returns something the parser is not prepared for. If that's the case, please open a bug report at: http://trac.wxwidgets.org

Re: wxFTP::PWD() error

Posted: Fri Sep 23, 2016 10:30 am
by Oleg
After that step program is going to crash:
ppointer.png
ppointer.png (30.73 KiB) Viewed 2104 times

Re: wxFTP::PWD() error

Posted: Fri Sep 23, 2016 11:22 am
by doublemax
It's a little hard to tell what exactly is going on without being able to trace through it myself. But i looks like a bug in the parsing code. So i'd suggest to open a bug report.

Re: wxFTP::PWD() error

Posted: Fri Sep 23, 2016 11:24 am
by Oleg
Ok, thanks.

Re: wxFTP::PWD() error

Posted: Fri Sep 23, 2016 12:32 pm
by Oleg

Re: wxFTP::PWD() error

Posted: Fri Sep 23, 2016 1:56 pm
by doublemax
Thanks. I wouldn't expect a fix anytime soon. So you better find a workaround or try to fix it yourself.

Re: wxFTP::PWD() error

Posted: Fri Sep 23, 2016 2:11 pm
by ONEEYEMAN
Oleg,
What's you OS/compiler/wx version?
Can you step inside the offending function and see where exactly the crash occurred?

Thank you.

Re: wxFTP::PWD() error

Posted: Fri Sep 23, 2016 2:26 pm
by Oleg
OS: Windows 7 Professional x64
Compiler: Microsoft Visual Studio 2013
wxVersion: wxWidgets-3.1.0

ONEEYEMAN wrote:Can you step inside the offending function and see where exactly the crash occurred?

Yes, at this point:
ppointer.png
ppointer.png (30.73 KiB) Viewed 2070 times

Re: wxFTP::PWD() error  [SOLVED]

Posted: Mon Sep 26, 2016 7:21 am
by doublemax

Re: wxFTP::PWD() error

Posted: Mon Sep 26, 2016 7:32 am
by Oleg
Great! Thanks.