diff libinterp/corefcn/urlwrite.cc @ 19438:c2f4f6eb5907

A few more instances of stricter input validation for strings (bug #42651). * load-path.cc (Faddpath, Frmpath): Use is_string() to check string input. * urlwrite.cc (Furlwrite, Furlread): Use is_string() to check string input. * variables.cc (extract_function, set_internal_variable): Use is_string() to check string input. * ov-class.cc (Fclass): Use is_string() to check string input.
author Rik <rik@octave.org>
date Tue, 16 Dec 2014 12:07:32 -0800
parents 03067dab10ca
children db92e7e28e1f
line wrap: on
line diff
--- a/libinterp/corefcn/urlwrite.cc	Tue Dec 16 09:21:29 2014 -0800
+++ b/libinterp/corefcn/urlwrite.cc	Tue Dec 16 12:07:32 2014 -0800
@@ -346,32 +346,37 @@
       return retval;
     }
 
-  std::string url = args(0).string_value ();
-
-  if (error_state)
+  if (! args(0).is_string ()) 
     {
       error ("urlwrite: URL must be a string");
       return retval;
     }
 
-  // name to store the file if download is succesful
-  // FIXME: Maybe use is_string () for better input validation.
-  std::string filename = args(1).string_value ();
+  std::string url = args(0).string_value ();
 
-  if (error_state)
+  if (! args(1).is_string ()) 
     {
       error ("urlwrite: LOCALFILE must be a string");
       return retval;
     }
 
+  // name to store the file if download is succesful
+  std::string filename = args(1).string_value ();
+
   std::string method;
   Array<std::string> param;
 
   if (nargin == 4)
     {
+      if (! args(2).is_string ()) 
+        {
+          error ("urlwrite: METHOD must be a string");
+          return retval;
+        }
+
       method = args(2).string_value ();
 
-      if (error_state || (method != "get" && method != "post"))
+      if (method != "get" && method != "post")
         {
           error ("urlwrite: METHOD must be \"get\" or \"post\"");
           return retval;
@@ -498,24 +503,28 @@
       return retval;
     }
 
-  // FIXME: Maybe use is_string () for better input validation.
-  std::string url = args(0).string_value ();
-
-  if (error_state)
+  if (! args(0).is_string ()) 
     {
       error ("urlread: URL must be a string");
       return retval;
     }
 
+  std::string url = args(0).string_value ();
+
   std::string method;
   Array<std::string> param;
 
   if (nargin == 3)
     {
-      // FIXME: Maybe use is_string () for better input validation.
+      if (! args(1).is_string ()) 
+        {
+          error ("urlread: METHOD must be a string");
+          return retval;
+        }
+
       method = args(1).string_value ();
 
-      if (error_state || (method != "get" && method != "post"))
+      if (method != "get" && method != "post")
         {
           error ("urlread: METHOD must be \"get\" or \"post\"");
           return retval;