Re: timeout fix for linux

[email protected] (Wietse Venema) Fri, 19 Jan 2007 07:53:12 -0500 (EST)
Newsgroups gmane.comp.security.forensics.tct
Message-ID <[email protected]>
Keresztfalvi Laszlo:
[ Charset ISO-8859-2 unsupported, converting... ]
> Hello,
> 
> since I did not find other address to send a patch, here it is:
> 
> in src/misc/timeout.c (at least on Linux):

This patch does not correctly report that the process was killed
by a signal.

	Wietse

> #include <sys/wait.h> and returning WEXITSTATUS(status) is required to correctly return the executed command's 
> exit value.
> 
> Best regards,
> Laszlo

[ text/x-patch is unsupported, treating like TEXT/PLAIN ]

> diff -ru tct-1.16/src/misc/timeout.c tct-1.16-fixed/src/misc/timeout.c
> --- tct-1.16/src/misc/timeout.c	2004-10-18 16:59:31.000000000 +0200
> +++ tct-1.16-fixed/src/misc/timeout.c	2007-01-19 11:03:58.000000000 +0100
> @@ -34,6 +34,7 @@
>  /* System libraries. */
>  
>  #include <sys/types.h>
> +#include <sys/wait.h>
>  #include <signal.h>
>  #include <stdlib.h>
>  #include <unistd.h>
> @@ -107,6 +108,6 @@
>  	alarm(time_to_run);
>  	while ((pid = wait(&status)) != -1 && pid != child_pid)
>  	     /* void */ ;
> -	return (pid == child_pid ? status : -1);
> +	return (pid == child_pid ? WEXITSTATUS(status) : -1);
>      }
>  }