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]
Date:   Mon, 2 Mar 2020 16:27:41 +0100
From:   Jiri Olsa <jolsa@...hat.com>
To:     Arnaldo Carvalho de Melo <acme@...nel.org>
Cc:     Jiri Olsa <jolsa@...nel.org>, Namhyung Kim <namhyung@...nel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] perf parse-events: Use asprintf() instead of strncpy()
 for tracepoints

On Mon, Mar 02, 2020 at 11:55:35AM -0300, Arnaldo Carvalho de Melo wrote:

SNIP

>       |          ^~~~~~
>   CC       /tmp/build/perf/util/call-path.o
> 
> So I replaced it with asprintf to make the code shorter, use a bit less
> memory and deal with the above problem, ok?
> 
> - Arnaldo
> 
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index c01ba6f8fdad..a14995835d85 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -257,21 +257,15 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
>  				path = zalloc(sizeof(*path));
>  				if (!path)
>  					return NULL;
> -				path->system = malloc(MAX_EVENT_LENGTH);
> -				if (!path->system) {
> +				if (asprintf(&path->system, "%.*s", MAX_EVENT_LENGTH, sys_dirent->d_name) < 0) {
>  					free(path);
>  					return NULL;
>  				}
> -				path->name = malloc(MAX_EVENT_LENGTH);
> -				if (!path->name) {
> +				if (asprintf(&path->name, "%.*s", MAX_EVENT_LENGTH, evt_dirent->d_name) < 0) {
>  					zfree(&path->system);
>  					free(path);
>  					return NULL;
>  				}
> -				strncpy(path->system, sys_dirent->d_name,
> -					MAX_EVENT_LENGTH);
> -				strncpy(path->name, evt_dirent->d_name,
> -					MAX_EVENT_LENGTH);

looks good to me, and we can probably remove MAX_EVENT_LENGTH as well?

jirka

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ