Mercurial > hg > octave-jordi
changeset 18286:9a43d8d6e29e stable
avoid startup crash if curl library is not available (bug #41067)
* main-window.cc (news_reader::process): Don't attempt to use
url_transfer object unless it is valid.
* urlwrite.cc (ch_manager::do_make_curl_handle, Furlwrite, Furlread):
Likewise.
* url-transfer.cc (url_transfer::url_transfer): Don't call
disabled_error.
(disabled_error): Delete unused function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 15 Jan 2014 15:22:03 -0500 |
parents | de72c443ed3f |
children | 78c3b4cb0c7f b14cdae65abd |
files | libgui/src/main-window.cc libinterp/corefcn/urlwrite.cc liboctave/util/url-transfer.cc |
diffstat | 3 files changed, 59 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -367,11 +367,14 @@ std::ostringstream buf; url_transfer octave_dot_org (url.toStdString (), buf); - Array<std::string> param; - octave_dot_org.http_get (param); - - if (octave_dot_org.good ()) - html_text = QString::fromStdString (buf.str ()); + if (octave_dot_org.is_valid ()) + { + Array<std::string> param; + octave_dot_org.http_get (param); + + if (octave_dot_org.good ()) + html_text = QString::fromStdString (buf.str ()); + } if (html_text.contains ("this-is-the-gnu-octave-community-news-page")) {
--- a/libinterp/corefcn/urlwrite.cc +++ b/libinterp/corefcn/urlwrite.cc @@ -189,10 +189,15 @@ url_transfer obj (host, user, passwd, os); - if (! error_state) - handle_map[h] = obj; + if (obj.is_valid ()) + { + if (! error_state) + handle_map[h] = obj; + else + h = curl_handle (); + } else - h = curl_handle (); + error ("support for url transfers was disabled when Octave was built"); return h; } @@ -413,31 +418,36 @@ url_transfer curl = url_transfer (url, ofile); - curl.http_action (param, method); - - ofile.close (); + if (! curl.is_valid ()) + { + curl.http_action (param, method); - if (curl.good ()) - frame.discard (); + ofile.close (); - if (nargout > 0) - { if (curl.good ()) + frame.discard (); + + if (nargout > 0) { - retval(2) = std::string (); - retval(1) = true; - retval(0) = octave_env::make_absolute (filename); + if (curl.good ()) + { + retval(2) = std::string (); + retval(1) = true; + retval(0) = octave_env::make_absolute (filename); + } + else + { + retval(2) = curl.lasterror (); + retval(1) = false; + retval(0) = std::string (); + } } - else - { - retval(2) = curl.lasterror (); - retval(1) = false; - retval(0) = std::string (); - } + + if (nargout < 2 && ! curl.good ()) + error ("urlwrite: %s", curl.lasterror ().c_str ()); } - - if (nargout < 2 && ! curl.good ()) - error ("urlwrite: %s", curl.lasterror ().c_str ()); + else + error ("support for url transfers was disabled when Octave was built"); return retval; } @@ -540,21 +550,26 @@ url_transfer curl = url_transfer (url, buf); - curl.http_action (param, method); + if (curl.is_valid ()) + { + curl.http_action (param, method); - if (curl.good ()) - { - if (nargout > 0) + if (curl.good ()) { - // Return empty string if no error occured. - retval(2) = curl.good () ? "" : curl.lasterror (); - retval(1) = curl.good (); - retval(0) = buf.str (); + if (nargout > 0) + { + // Return empty string if no error occured. + retval(2) = curl.good () ? "" : curl.lasterror (); + retval(1) = curl.good (); + retval(0) = buf.str (); + } } + + if (nargout < 2 && ! curl.good ()) + error ("urlread: %s", curl.lasterror().c_str()); } - - if (nargout < 2 && ! curl.good ()) - error ("urlread: %s", curl.lasterror().c_str()); + else + error ("support for url transfers was disabled when Octave was built"); return retval; }
--- a/liboctave/util/url-transfer.cc +++ b/liboctave/util/url-transfer.cc @@ -767,15 +767,6 @@ #undef SETOPT -#else - -static void -disabled_error (void) -{ - (*current_liboctave_error_handler) - ("support for url transfers was disabled when Octave was built"); -} - #endif #if defined (HAVE_CURL) @@ -785,27 +776,15 @@ #endif url_transfer::url_transfer (void) : rep (new REP_CLASS ()) -{ -#if !defined (HAVE_CURL) - disabled_error (); -#endif -} +{ } url_transfer::url_transfer (const std::string& host, const std::string& user, const std::string& passwd, std::ostream& os) : rep (new REP_CLASS (host, user, passwd, os)) -{ -#if !defined (HAVE_CURL) - disabled_error (); -#endif -} +{ } url_transfer::url_transfer (const std::string& url, std::ostream& os) : rep (new REP_CLASS (url, os)) -{ -#if !defined (HAVE_CURL) - disabled_error (); -#endif -} +{ } #undef REP_CLASS