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] [day] [month] [year] [list]
Message-ID: <CAP-5=fUfDtO5oVoxsCeYEuiE_kEYCOjU7tJjVS68nQ3cxo_Uqg@mail.gmail.com>
Date: Tue, 7 Oct 2025 08:15:39 -0700
From: Ian Rogers <irogers@...gle.com>
To: James Clark <james.clark@...aro.org>
Cc: linux-perf-users@...r.kernel.org, namhyung@...nel.org, acme@...nel.org, 
	Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>, 
	Mark Rutland <mark.rutland@....com>, 
	Alexander Shishkin <alexander.shishkin@...ux.intel.com>, Jiri Olsa <jolsa@...nel.org>, 
	Adrian Hunter <adrian.hunter@...el.com>, Charlie Jenkins <charlie@...osinc.com>, 
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] perf tests: use strdup() in "Object code reading"

On Tue, Oct 7, 2025 at 7:09 AM James Clark <james.clark@...aro.org> wrote:
>
> Use strdup() instead of fixed PATH_MAX buffer for storing paths to not
> waste memory.
>
> Suggested-by: Ian Rogers <irogers@...gle.com>
> Signed-off-by: James Clark <james.clark@...aro.org>
> ---
> Applies on top of: https://lore.kernel.org/linux-perf-users/CAP-5=fV1N-j+f4GBFnDWsmoMZcz_k0U=nu1A7NZz-g4gzCH4KA@mail.gmail.com/T/#t
>
>  tools/perf/tests/code-reading.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
> index 4c9fbf6965c4..88408eea9e41 100644
> --- a/tools/perf/tests/code-reading.c
> +++ b/tools/perf/tests/code-reading.c
> @@ -43,7 +43,7 @@
>  struct tested_section {
>         struct rb_node rb_node;
>         u64 addr;
> -       char path[PATH_MAX];
> +       char *path;
>  };
>
>  static bool tested_code_insert_or_exists(const char *path, u64 addr,
> @@ -79,7 +79,7 @@ static bool tested_code_insert_or_exists(const char *path, u64 addr,
>                 return true;
>
>         data->addr = addr;
> -       strlcpy(data->path, path, sizeof(data->path));
> +       data->path = strdup(path);

nit: should really check the memory allocation succeeded
```
if (!data->path) {
   free(data);
   return true;
}
```

Otherwise:
Reviewed-by: Ian Rogers <irogers@...gle.com>

Thanks,
Ian

>         rb_link_node(&data->rb_node, parent, node);
>         rb_insert_color(&data->rb_node, tested_sections);
>         return false;
> @@ -94,6 +94,7 @@ static void tested_sections__free(struct rb_root *root)
>                                                      rb_node);
>
>                 rb_erase(node, root);
> +               free(ts->path);
>                 free(ts);
>         }
>  }
> --
> 2.34.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ