From 03c7cbfcf9a150c5a24a0bd1f707d44b4ef3efc1 Mon Sep 17 00:00:00 2001 From: bje Date: Tue, 22 May 2001 12:17:13 +0000 Subject: [PATCH] 2001-05-22 Ben Elliston * compConfig.cxx (cfgroot_component::num_invalid_chars): New. (cfgroot_component::configure): Initialise it. (cfgroot_component::max_invalid_chars): New enumerator. (cfgroot_component::emit_invalid_char_error): New method. (cfgroot_component::consume_token): Factor out common error handling code into cfgroot_component::emit_invalid_char_error. (cfgroot_component::parse): Stop parsing if too many invalid character codes are encountered and emit an error message. --- sid/component/cfgroot/ChangeLog | 11 ++++++++++ sid/component/cfgroot/compConfig.cxx | 41 +++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/sid/component/cfgroot/ChangeLog b/sid/component/cfgroot/ChangeLog index 01986232c7..86b49840b2 100644 --- a/sid/component/cfgroot/ChangeLog +++ b/sid/component/cfgroot/ChangeLog @@ -1,5 +1,16 @@ 2001-05-22 Ben Elliston + * compConfig.cxx (cfgroot_component::num_invalid_chars): New. + (cfgroot_component::configure): Initialise it. + (cfgroot_component::max_invalid_chars): New enumerator. + (cfgroot_component::emit_invalid_char_error): New method. + (cfgroot_component::consume_token): Factor out common error + handling code into cfgroot_component::emit_invalid_char_error. + (cfgroot_component::parse): Stop parsing if too many invalid + character codes are encountered and emit an error message. + +2001-05-22 Ben Elliston + * compConfig.cxx (cfgroot_component::run): Remove timebomb logic. * configure.in (--enable-timebomb): Remove. * configure: Regenerate. diff --git a/sid/component/cfgroot/compConfig.cxx b/sid/component/cfgroot/compConfig.cxx index 5d7177c966..3b126465a1 100644 --- a/sid/component/cfgroot/compConfig.cxx +++ b/sid/component/cfgroot/compConfig.cxx @@ -1,7 +1,7 @@ // compConfig.cxx - The cfgroot component: configuration parsing, root // of component creation and management. -*- C++ -*- -// Copyright (C) 1999-2001 Red Hat. +// Copyright (C) 1999, 2000, 2001 Red Hat. // This file is part of SID and is licensed under the GPL. // See the file COPYING.SID for conditions for redistribution. @@ -107,6 +107,7 @@ protected: unsigned line_num; bool parse(istream&); string current_token; + int num_invalid_chars; void consume_token(istream&); string next_token(istream&); bool parse_command(istream&); @@ -153,10 +154,16 @@ private: bool autoprint_p; bool persistent_p; + // max number of invalid chars which may be in a config file + enum { max_invalid_chars = 12 }; + // a general purpose method for emitting error messages // FIXME: i18n void emit_error(const string& msg); + // emit an error for invalid character codes found in the input + void emit_invalid_char_error (const char ch); + // track component name -> component object pointer typedef map component_map_t; component_map_t component_map; @@ -185,6 +192,16 @@ cfgroot_component::emit_error(const string& msg) } void +cfgroot_component::emit_invalid_char_error (const char ch) +{ + if (++num_invalid_chars < max_invalid_chars) + emit_error(string("invalid character [") + + make_numeric_attribute(host_int_2((unsigned char) ch), + ios::hex|ios::showbase) + + string("] ignored.")); +} + +void cfgroot_component::consume_token(istream& input) // lexer { string buf; @@ -254,12 +271,7 @@ cfgroot_component::consume_token(istream& input) // lexer do { if (!isprint(ch)) - { - emit_error(string("invalid character [") + - make_numeric_attribute(host_int_2((unsigned char) ch), - ios::hex|ios::showbase) + - string("] ignored.")); - } + emit_invalid_char_error (ch); else buf += ch; @@ -272,11 +284,8 @@ cfgroot_component::consume_token(istream& input) // lexer break; // end of token } else // control code - { - emit_error(string("invalid character [") + - make_numeric_attribute(host_int_2((unsigned char) ch), - ios::hex|ios::showbase) + - string("] ignored.")); + { + emit_invalid_char_error (ch); continue; } } @@ -461,6 +470,13 @@ cfgroot_component::parse(istream& cfile) { bool this_ok = this->parse_command(cfile); cumulative_ok = cumulative_ok && this_ok; + + if (num_invalid_chars >= max_invalid_chars) + { + emit_error ("too many invalid characters--possibly a binary file?"); + cumulative_ok = false; + break; + } } return cumulative_ok; } @@ -483,6 +499,7 @@ cfgroot_component::configure(const std::string& name) this->config_file_history += this->config_file; unsigned last_line_num = this->line_num; this->line_num = 1; + num_invalid_chars = 0; ifstream cfile(find_sid_data_file(this->config_file).c_str()); if(! cfile.good()) -- 2.11.0