diff options
| -rw-r--r-- | lib/tests/test_utils.c | 12 | ||||
| -rw-r--r-- | 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 ce79fc64..4f761a6d 100644 --- a/lib/tests/test_utils.c +++ b/lib/tests/test_utils.c | |||
| @@ -308,11 +308,19 @@ main (int argc, char **argv) | |||
| 308 | ok( !strcmp(temp_state_key->name, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got generated filename" ); | 308 | ok( !strcmp(temp_state_key->name, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got generated filename" ); |
| 309 | 309 | ||
| 310 | 310 | ||
| 311 | np_enable_state("bad^chars$in@here", 77); | 311 | np_enable_state("allowedchars_in_keyname", 77); |
| 312 | temp_state_key = this_nagios_plugin->state; | 312 | temp_state_key = this_nagios_plugin->state; |
| 313 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | 313 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); |
| 314 | ok( !strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars" ); | ||
| 315 | ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/allowedchars_in_keyname"), "Got internal filename" ); | ||
| 316 | |||
| 317 | |||
| 318 | /* Don't do this test just yet. Will die */ | ||
| 319 | /* | ||
| 320 | np_enable_state("bad^chars$in@here", 77); | ||
| 321 | temp_state_key = this_nagios_plugin->state; | ||
| 314 | ok( !strcmp(temp_state_key->name, "bad_chars_in_here"), "Got key name with bad chars replaced" ); | 322 | ok( !strcmp(temp_state_key->name, "bad_chars_in_here"), "Got key name with bad chars replaced" ); |
| 315 | ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/bad_chars_in_here"), "Got internal filename" ); | 323 | */ |
| 316 | 324 | ||
| 317 | np_enable_state("funnykeyname", 54); | 325 | np_enable_state("funnykeyname", 54); |
| 318 | temp_state_key = this_nagios_plugin->state; | 326 | temp_state_key = this_nagios_plugin->state; |
diff --git a/lib/utils_base.c b/lib/utils_base.c index 70279178..4e8d2ef7 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) { | |||
| 432 | if(temp_keyname==NULL) | 432 | if(temp_keyname==NULL) |
| 433 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); | 433 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); |
| 434 | } | 434 | } |
| 435 | /* Convert all non-alphanumerics to _ */ | 435 | /* Die if invalid characters used for keyname */ |
| 436 | p = temp_keyname; | 436 | p = temp_keyname; |
| 437 | while(*p!='\0') { | 437 | while(*p!='\0') { |
| 438 | if(! isalnum(*p)) { | 438 | if(! (isalnum(*p) || *p == '_')) { |
| 439 | *p='_'; | 439 | die(STATE_UNKNOWN, _("Invalid character for keyname - only alphanumerics or '_'")); |
| 440 | } | 440 | } |
| 441 | p++; | 441 | p++; |
| 442 | } | 442 | } |
