# HG changeset patch # User John W. Eaton # Date 1234852390 18000 # Node ID 9e3111d203c0d3c1899dfa6a4956b0a43d2acf0b # Parent aeedc045cfe316ab3e67ae8977a6a6eb13438f10 disallow reading from stdin while running interactively diff -r aeedc045cfe3 -r 9e3111d203c0 src/ChangeLog --- a/src/ChangeLog Tue Feb 17 00:43:13 2009 -0500 +++ b/src/ChangeLog Tue Feb 17 01:33:10 2009 -0500 @@ -1,5 +1,14 @@ 2009-02-17 John W. Eaton + * file-io.cc (Ffscanf, Fsscanf): Check error_state after call to + octave_stream::scanf. + (Ffgetl): Check error state after call to octave_stream::getl. + (Ffgets): Check error state after call to octave_stream::gets. + + * oct-stream.cc (octave_base_stream::do_gets, + octave_base_stream::do_scanf): + Disallow reading from stdin when running interactively. + * toplev.cc (octave_config_info): Add CARBON_LIBS, X11_INCFLAGS, and X11_LIBS to the struct. * oct-conf.h.in (OCTAVE_CONF_CARBON_LIBS, diff -r aeedc045cfe3 -r 9e3111d203c0 src/file-io.cc --- a/src/file-io.cc Tue Feb 17 00:43:13 2009 -0500 +++ b/src/file-io.cc Tue Feb 17 01:33:10 2009 -0500 @@ -335,7 +335,7 @@ std::string tmp = os.getl (len_arg, err, who); - if (! err) + if (! (error_state || err)) { retval(1) = tmp.length (); retval(0) = tmp; @@ -383,7 +383,7 @@ std::string tmp = os.gets (len_arg, err, who); - if (! err) + if (! (error_state || err)) { retval(1) = tmp.length (); retval(0) = tmp; @@ -1118,8 +1118,11 @@ { octave_value tmp = os.scanf (args(1), size, count, who); - retval(1) = count; - retval(0) = tmp; + if (! error_state) + { + retval(1) = count; + retval(0) = tmp; + } } } else @@ -1198,15 +1201,18 @@ octave_value tmp = os.scanf (args(1), size, count, who); - // FIXME -- is this the right thing to do? - // Extract error message first, because getting - // position will clear it. - std::string errmsg = os.error (); + if (! error_state) + { + // FIXME -- is this the right thing to do? + // Extract error message first, because getting + // position will clear it. + std::string errmsg = os.error (); - retval(3) = os.tell () + 1; - retval(2) = errmsg; - retval(1) = count; - retval(0) = tmp; + retval(3) = os.tell () + 1; + retval(2) = errmsg; + retval(1) = count; + retval(0) = tmp; + } } else ::error ("%s: format must be a string", who.c_str ()); diff -r aeedc045cfe3 -r 9e3111d203c0 src/oct-stream.cc --- a/src/oct-stream.cc Tue Feb 17 00:43:13 2009 -0500 +++ b/src/oct-stream.cc Tue Feb 17 01:33:10 2009 -0500 @@ -964,6 +964,14 @@ { std::string retval; + if ((interactive || forced_interactive) && file_number () == 0) + { + ::error ("%s: unable to read from stdin while running interactively", + who.c_str ()); + + return retval; + } + err = false; std::istream *isp = input_stream (); @@ -1651,14 +1659,22 @@ octave_idx_type nr, octave_idx_type nc, bool one_elt_size_spec, octave_idx_type& conversion_count, const std::string& who) { + octave_value retval = Matrix (); + + if ((interactive || forced_interactive) && file_number () == 0) + { + ::error ("%s: unable to read from stdin while running interactively", + who.c_str ()); + + return retval; + } + conversion_count = 0; int nconv = fmt_list.num_conversions (); octave_idx_type data_index = 0; - octave_value retval = Matrix (); - if (nr == 0 || nc == 0) { if (one_elt_size_spec)