[patch] Fix compiler warnings

Michael Friedrich michael.friedrich at univie.ac.at
Wed Sep 22 09:19:18 CEST 2010


Hi,

Stephen Gran wrote:
> diff --git a/cgi/cmd.c b/cgi/cmd.c
> index df5fc72..2a37a08 100644
> --- a/cgi/cmd.c
> +++ b/cgi/cmd.c
> @@ -1891,6 +1891,26 @@ void commit_command_data(int cmd){
>   	return;
>           }
>
> +static int cmd_submit(int id){
> +	char cmd[MAX_EXTERNAL_COMMAND_LENGTH];
> +	const char *command;
> +	int len;
> +
> +	command = extcmd_get_name(id);
> +	/*
> +	 * We disallow sending 'CHANGE' commands from the cgi's
> +	 * until we do proper session handling to prevent cross-site
> +	 * request forgery
> +	 */
> +	if (!command || (strlen(command)>  6&&  !memcmp("CHANGE", command, 6)))
> +		return ERROR;
> +
> +	len = snprintf(cmd, sizeof(cmd) - 1, "[%lu] %s;", time(NULL), command);
> +	if (len<  0)
> +		return ERROR;
> +
> +	return write_command_to_file(cmd);
> +	}
>
>   __attribute__((format(printf, 2, 3)))
>   static int cmd_submitf(int id, const char *fmt, ...){
> @@ -1925,7 +1945,6 @@ static int cmd_submitf(int id, const char *fmt, ...){
>
>   /* commits a command for processing */
>   int commit_command(int cmd){
> -	char command_buffer[MAX_INPUT_BUFFER];
>   	time_t current_time;
>   	time_t scheduled_time;
>   	time_t notification_time;
> @@ -1980,7 +1999,7 @@ int commit_command(int cmd){
>   	case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
>   	case CMD_START_OBSESSING_OVER_HOST_CHECKS:
>   	case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
> -		result = cmd_submitf(cmd,"");
> +		result = cmd_submit(cmd);
>   		break;
>
>   		/** simple host commands **/
>    

Instead of adding another function doing pretty much the same, but 
without any variable arguments on the function call, you might have a 
look at Andreas Ericsson's patch by checking fmt for NULL, and replacing 
the string literal by NULL.

http://git.op5.org/git/?p=nagios.git;a=commit;h=bd8eb5927b2e2fe22b36601181d138acbba27e3a

It's nicely resolved and keeps the upstream clean for other NULL'ed 
arguments.

Kind regards,
Michael

-- 
DI (FH) Michael Friedrich

Vienna University Computer Center
Universitaetsstrasse 7 A-1010 Vienna, Austria

email: 	michael.friedrich at univie.ac.at
phone: 	+43 1 4277 14359
fax: 	+43 1 4277 14279
web:	http://www.univie.ac.at/zid

Icinga Core&  IDOUtils Developer
http://www.icinga.org


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev




More information about the Developers mailing list