[PATCH evemu] evemu-record.c: fix memory access in error path

Peter Hutterer peter.hutterer at who-t.net
Sun Sep 17 11:49:25 UTC 2017


On Sun, Sep 17, 2017 at 01:07:15PM +0200, Martin Kepplinger wrote:
> In case the output file could not have been opened, it is accessed anyways
> although it's zero, resulting in a segmentation fault.
> 
> So let's free it in the out-path only if allocated before.
> 
> Signed-off-by: Martin Kepplinger <martink at posteo.de>

> ---
> 
> Hi Peter,
> 
> Thanks for pointing that out. You're right, only fclose(NULL) is a
> problem here. Tested.

many thanks! pushed

Cheers,
   Peter

> 
> thanks,
> 
>                          martin
> 
> 
>  tools/evemu-record.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/evemu-record.c b/tools/evemu-record.c
> index 56572bb..40693ff 100644
> --- a/tools/evemu-record.c
> +++ b/tools/evemu-record.c
> @@ -339,7 +339,7 @@ int main(int argc, char *argv[])
>  out:
>  	free(device);
>  	close(fd);
> -	if (output != stdout) {
> +	if (output && output != stdout) {
>  		fclose(output);
>  		output = stdout;
>  	}
> -- 
> 2.11.0
> 


More information about the Input-tools mailing list