lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1335198066.28106.103.camel@gandalf.stny.rr.com>
Date:	Mon, 23 Apr 2012 12:21:06 -0400
From:	Steven Rostedt <rostedt@...dmis.org>
To:	Namhyung Kim <namhyung.kim@....com>
Cc:	Frederic Weisbecker <fweisbec@...il.com>,
	Namhyung Kim <namhyung@...il.com>,
	Ingo Molnar <mingo@...nel.org>,
	Arnaldo Carvalho de Melo <acme@...radead.org>,
	Borislav Petkov <bp@...en8.de>,
	David Ahern <dsahern@...il.com>,
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 01/11] parse-events: Free flag/sym field on failure path

On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
> If parsing flag/sym field failed after allocating it, it
> should be freed.
> 
> Signed-off-by: Namhyung Kim <namhyung.kim@....com>
> ---
>  parse-events.c |   14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/parse-events.c b/parse-events.c
> index bd078ba..81e6581 100644
> --- a/parse-events.c
> +++ b/parse-events.c
> @@ -2166,10 +2166,10 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
>  
>  		value = arg_eval(arg);
>  		if (value == NULL)
> -			goto out_free;
> +			goto out_free_field;

Instead of adding more goto's what, before the first goto "out_free"
add:

	field = NULL;

and since the field is allocated and also memset to zero, we could do in
the out_free:

	if (field) {
		free(field->value);
		free(field);
	}

I think that would be cleaner.

-- Steve

>  		field->value = strdup(value);
>  		if (field->value == NULL)
> -			goto out_free;
> +			goto out_free_field;
>  
>  		free_arg(arg);
>  		arg = alloc_arg();
> @@ -2177,14 +2177,14 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
>  		free_token(token);
>  		type = process_arg(event, arg, &token);
>  		if (test_type_token(type, token, EVENT_OP, "}"))
> -			goto out_free;
> +			goto out_free_field_value;
>  
>  		value = arg_eval(arg);
>  		if (value == NULL)
> -			goto out_free;
> +			goto out_free_field_value;
>  		field->str = strdup(value);
>  		if (field->str == NULL)
> -			goto out_free;
> +			goto out_free_field_value;
>  		free_arg(arg);
>  		arg = NULL;
>  
> @@ -2198,6 +2198,10 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
>  	*tok = token;
>  	return type;
>  
> +out_free_field_value:
> +	free(field->value);
> +out_free_field:
> +	free(field);
>  out_free:
>  	free_arg(arg);
>  	free_token(token);


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ