[sage] Hilfe bei Nagios-Addon "NSCA" für IPv6

Maximilian Wilhelm max at rfc2324.org
Tue Sep 6 23:34:24 CEST 2011


Anno domini 2011 Johannes Hubertz scripsit:

> Es folgt ein diff auf nsca.c, damit funktioniert es bei mir ebenfalls 
> unter squeeze.

Das ist vor allem eine nette Vorlage für einen Buffer overflow und
funktioniert nicht mehr, wenn keine server_address in der config
angegeben ist.

man getaddrinfo

  If the AI_PASSIVE flag is specified in hints.ai_flags, and node is
  NULL, then the returned socket addresses will be suitable for
  bind(2)ing a socket that will accept(2) connections.

>  char *server_port=DEFAULT_SERVER_PORT;
> +// this is possibly as wrong as server_address was broken,
> +// but caused no sigsegv during my tests ;-)
> +
> +/* Johannes Hubertz added this comment on Sept. 6th 2011 because of 
> sigsegv
> + * hello c-guys,
> + * its a common misbehavior to store strings in pointers
> + * and usually it fails for ?unknown? reason 8-()
> + * next line is wrong in mind, not in syntax! Believe it!

Warum ist es ein misbehavior Pointer zu nutzen? Man sollte nur
dafür Sorgen, dass der Speicher auch da ist, dann tut das prima.
As in:

  server_address = strdup (varvalue);

(Ok, dass server_address nicht ge-free()-ed wird, sondern einfach auf
 NULL gesetzt wird ist 'nen Bug, aber das ist 'ne andere Geschichte.)

>  char    *server_address=NULL;
> + * make it better by using arrays of chars, that helps!  */
> +char   server_address[MAX_INPUT_BUFFER];
> +
>  static int socket_timeout=DEFAULT_SOCKET_TIMEOUT;
>  static int log_facility=LOG_DAEMON;

> @@ -381,7 +392,8 @@ static int read_config_file(char *filename){
>  			server_port=strdup(varvalue);
>  
>  		else if(!strcmp(varname,"server_address")){
> -                        
> strncpy(server_address,varvalue,sizeof(server_address) - 1);
> +                        //strncpy(server_address,varvalue,sizeof(server_address) - 
> 1);
> +			strcpy(server_address, varvalue);
>                          server_address[sizeof(server_address)-1]='\0';
>                          }
>  		else if(strstr(input_buffer,"command_file")){
> @@ -778,7 +790,8 @@ static void wait_for_connections(void) {
>  	addrinfo.ai_protocol=IPPROTO_TCP;
>  
>  	if(!server_address || !strlen(server_address)) {
> -		server_address = NULL;
> +		//server_address = NULL; see comment at definition of this var
> +		memset(&server_address[0], 0, sizeof(char));
>  		addrinfo.ai_flags=AI_PASSIVE;
>  		}
>  	if (rval = getaddrinfo(server_address, server_port, &addrinfo, 
> &res) != 0) {
> --------------------8<----------------8<------------------8<---

> Das ist immer noch reichlich haesslich, aber es tut.

Naja.

Ciao
Max
-- 
"Ich habe eher spontan mitbestellt, ohne genau zu wissen, was ich da gerade kaufe.
 Immer noch besser, als Schuhe zu kaufen."
  -- uschebit zum Thema SheevaPlug



More information about the SAGE mailing list