diff libinterp/corefcn/urlwrite.cc @ 18287: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 870f3e12e163
children b522d04382cf
line wrap: on
line diff
--- a/libinterp/corefcn/urlwrite.cc	Tue Jan 14 22:13:12 2014 -0500
+++ b/libinterp/corefcn/urlwrite.cc	Wed Jan 15 15:22:03 2014 -0500
@@ -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;
 }