Mercurial > octave-nkf
diff libinterp/corefcn/file-io.cc @ 19437:03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
* data.cc (get_sort_mode_option, Fissorted): Use is_string() to check string
input.
* debug.cc (Fdbstep): use "string" rather than "character string" in error
messages.
* error.cc (Flasterr, Flastwarn): use "string" rather than "character string"
in error messages.
* file-io.cc (do_stream_open, do_fread, do_fwrite, Fpopen, Ftempname,
Fmkstemp): Use is_string() to check string input.
* graphics.cc (Fgraphics_toolkit): Use is_string() to check string input.
Rephrase error message.
* help.cc (F__list_functions): Use is_string() to check string input.
* input.cc (Fyes_or_no): Use is_string() to check string input. Rephrase
error message.
* input.cc (Fadd_input_event_hook): Rephrase error message.
* load-path.cc (Fgenpath, Faddpath): Rephrase error message.
* matrix_type.cc (Fmatrix_type): Use is_string() to check string input.
* qz.cc (Fqz): Follow Octave coding convention for space after '!'.
* regexp.cc (parse_options): Use is_string() to check string input.
Rephrase error message.
* schur.cc (Fschur): Use is_string() to check string input.
* strfns.cc (Flist_in_columns): Use is_string() to check string input.
Rephrase error message.
* symtab.cc (Fignore_function_time_stamp): Use is_string() to check string
input. Rephrase error message.
* syscalls.cc (Fexec, Fpopen2, Fcanonicalize_file_name): Use is_string() to
check string input. Rephrase error message.
* sysdep.cc (Fsetenv): Use is_string() to check string input.
* time.cc (Fstrftime, Fstrptime): Use is_string() to check string input.
* toplev.cc (Fsystem, Fatexit): Use is_string() to check string input.
* urlwrite.cc (Furlwrite, Furlread): Rephrase error message.
* utils.cc (Ffile_in_path): Use is_string() to check string input. Rephrase
error message.
* variables.cc (extract_function): Add FIXME about potentially using is_string.
* variables.cc (do_isglobal, Fmunlock, Fmislocked): Use is_string() to check
string input.
* variables.cc (set_internal_variable): Rephrase error message.
* ov-base.cc (make_idx_args): Rephrase error message.
* ov-class.cc (octave_class::all_strings, Fclass): Rephrase error message.
* ov-fcn-handle.cc (Fstr2func): Use is_string() to check string input
* ov-java.cc (FjavaObject, FjavaMethod, F__java_get__, F__java_set__):
Use is_string() to check string input.
* ov.cc (Fdecode_subscripts): Use is_string() to check string input.
Rephrase error message.
* pt-idx.cc (tree_index_expression::get_struct_index): Rephrase error message.
* io.tst: Change %!warning test to %!error test to match stricter checking.
* system.tst: Change %!warning test for setenv to %!error test to match
stricter checking.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 16 Dec 2014 09:21:29 -0800 |
parents | 3b4d6780d6b8 |
children | 82f2a3437e02 |
line wrap: on
line diff
--- a/libinterp/corefcn/file-io.cc Mon Dec 15 22:16:25 2014 -0800 +++ b/libinterp/corefcn/file-io.cc Tue Dec 16 09:21:29 2014 -0800 @@ -557,18 +557,20 @@ fid = -1; - std::string name = tc_name.string_value (); - - if (! error_state) + if (tc_name.is_string ()) { - std::string mode = tc_mode.string_value (); + std::string name = tc_name.string_value (); - if (! error_state) + if (tc_mode.is_string ()) { - std::string arch = tc_arch.string_value (); + std::string mode = tc_mode.string_value (); - if (! error_state) - retval = do_stream_open (name, mode, arch, fid); + if (tc_arch.is_string ()) + { + std::string arch = tc_arch.string_value (); + + retval = do_stream_open (name, mode, arch, fid); + } else ::error ("%s: architecture type must be a string", fcn); } @@ -1371,10 +1373,10 @@ if (! error_state) { - std::string prec = prec_arg.string_value (); + if (prec_arg.is_string ()) + { + std::string prec = prec_arg.string_value (); - if (! error_state) - { int block_size = 1; oct_data_conv::data_type input_type; oct_data_conv::data_type output_type; @@ -1388,10 +1390,10 @@ if (! error_state) { - std::string arch = arch_arg.string_value (); + if (arch_arg.is_string ()) + { + std::string arch = arch_arg.string_value (); - if (! error_state) - { oct_mach_info::float_format flt_fmt = oct_mach_info::string_to_float_format (arch); @@ -1641,10 +1643,10 @@ { int retval = -1; - std::string prec = prec_arg.string_value (); + if (prec_arg.is_string ()) + { + std::string prec = prec_arg.string_value (); - if (! error_state) - { int block_size = 1; oct_data_conv::data_type output_type; @@ -1656,10 +1658,10 @@ if (! error_state) { - std::string arch = arch_arg.string_value (); + if (arch_arg.is_string ()) + { + std::string arch = arch_arg.string_value (); - if (! error_state) - { oct_mach_info::float_format flt_fmt = oct_mach_info::string_to_float_format (arch); @@ -1874,14 +1876,14 @@ if (nargin == 2) { - std::string name = args(0).string_value (); - - if (! error_state) + if (args(0).is_string ()) { - std::string mode = args(1).string_value (); + std::string name = args(0).string_value (); - if (! error_state) + if (args(1).is_string ()) { + std::string mode = args(1).string_value (); + if (mode == "r") { octave_stream ips = octave_iprocstream::create (name); @@ -1955,20 +1957,25 @@ if (len < 3) { - std::string dir = len > 0 ? args(0).string_value () : std::string (); - - if (! error_state) + std::string dir; + if (len > 0) { - std::string pfx - = len > 1 ? args(1).string_value () : std::string ("oct-"); + if (args(0).is_string ()) + dir = args(0).string_value (); + else + ::error ("DIR must be a string"); + } - if (! error_state) - retval = octave_tempnam (dir, pfx); + std::string pfx ("oct-"); + if (len > 1) + { + if (args(1).is_string ()) + pfx = args(1).string_value (); else ::error ("PREFIX must be a string"); } - else - ::error ("DIR argument must be a string"); + + retval = octave_tempnam (dir, pfx); } else print_usage (); @@ -2061,10 +2068,10 @@ if (nargin == 1 || nargin == 2) { - std::string tmpl8 = args(0).string_value (); + if (args(0).is_string ()) + { + std::string tmpl8 = args(0).string_value (); - if (! error_state) - { OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1); strcpy (tmp, tmpl8.c_str ());