[nagiosplug] Invalid chars in keyname now die()

"Ton Voon" <[email protected]>
Newsgroups gmane.network.nagios.plugins.cvs
Message-ID <[email protected]>
 Module: nagiosplug
 Branch: ton/state
 Commit: 10364a6004616c2e52852d80b1e1817056aa7119
 Author: Ton Voon <[email protected]>
   Date: Mon Jun 21 22:40:29 2010 +0100
    URL: http://nagiosplug.git.sf.net/git/gitweb.cgi?p=nagiosplug/nagiosplug;a=commit;h=10364a6

Invalid chars in keyname now die()

---

 lib/tests/test_utils.c |   12 ++++++++++--
 lib/utils_base.c       |    6 +++---
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c
index ce79fc6..4f761a6 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -308,11 +308,19 @@ main (int argc, char **argv)
 	ok( !strcmp(temp_state_key->name, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got generated filename" );
 
 
-	np_enable_state("bad^chars$in@here", 77);
+	np_enable_state("allowedchars_in_keyname", 77);
 	temp_state_key = this_nagios_plugin->state;
 	ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
+	ok( !strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars" );
+	ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/allowedchars_in_keyname"), "Got internal filename" );
+
+
+	/* Don't do this test just yet. Will die */
+	/*
+	np_enable_state("bad^chars$in@here", 77);
+	temp_state_key = this_nagios_plugin->state;
 	ok( !strcmp(temp_state_key->name, "bad_chars_in_here"), "Got key name with bad chars replaced" );
-	ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/bad_chars_in_here"), "Got internal filename" );
+	*/
 
 	np_enable_state("funnykeyname", 54);
 	temp_state_key = this_nagios_plugin->state;
diff --git a/lib/utils_base.c b/lib/utils_base.c
index 7027917..4e8d2ef 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -432,11 +432,11 @@ void np_enable_state(char *keyname, int expected_data_version) {
 		if(temp_keyname==NULL)
 			die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno));
 	}
-	/* Convert all non-alphanumerics to _ */
+	/* Die if invalid characters used for keyname */
 	p = temp_keyname;
 	while(*p!='\0') {
-		if(! isalnum(*p)) {
-			*p='_';
+		if(! (isalnum(*p) || *p == '_')) {
+			die(STATE_UNKNOWN, _("Invalid character for keyname - only alphanumerics or '_'"));
 		}
 		p++;
 	}


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.