From 10364a6004616c2e52852d80b1e1817056aa7119 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Mon, 21 Jun 2010 22:40:29 +0100 Subject: Invalid chars in keyname now die() 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++; } -- cgit v0.10-9-g596f