diff --git a/Changes b/Changes index 32f771d..f360673 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ This file documents the revision history for mod_gearman. +next: + - check_dummy: fix crash if output is empty + - check_dummy: support putting return code in quotes + 5.1.2 Thu Jun 29 11:02:35 CEST 2023 - neb: add internal check_dummy - change pid file location to /run in packages diff --git a/neb_module_naemon/mod_gearman.c b/neb_module_naemon/mod_gearman.c index 40f6e40..60499b5 100644 --- a/neb_module_naemon/mod_gearman.c +++ b/neb_module_naemon/mod_gearman.c @@ -1976,20 +1976,34 @@ static int try_check_dummy(const char * command_line, host * hst, service * svc) return(GM_ERROR); } + char *arg1 = strtok( NULL, " " ); + char *output = strtok( NULL, ""); if(arg1 == NULL) arg1 = ""; + // return code starts with double quote, take string until next double quote + if(arg1[0] == '"') { + arg1++; + arg1 = strtok( arg1, "\"" ); + if(arg1 == NULL) + arg1 = ""; + } + // return code starts with single quote, take string until next single quote + else if(arg1[0] == '\'') { + arg1++; + arg1 = strtok( arg1, "'" ); + } - char *output = strtok( NULL, ""); - if(output == NULL) { + if(output == NULL) output = ""; - } // string starts with double quote, take string until next double quote if(output[0] == '"') { output++; output = strtok( output, "\"" ); check_for_shell_chars = TRUE; + if(output == NULL) + output = ""; } // string starts with single quote, take string until next single quote else if(output[0] == '\'') {