[nagiosplug] Invalid chars in keyname now die()
Ton Voon
tonvoon at users.sourceforge.net
Tue Jun 22 12:50:50 CEST 2010
Module: nagiosplug
Branch: ton/state
Commit: 10364a6004616c2e52852d80b1e1817056aa7119
Author: Ton Voon <ton.voon at opsera.com>
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 at 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 at 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++;
}
More information about the Commits
mailing list