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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAP-5=fXzc4-U=g96dr7jzUHNKudcUh2JZW89BT8xs01Zfp7ZDw@mail.gmail.com>
Date:   Wed, 23 Nov 2022 15:22:01 -0800
From:   Ian Rogers <irogers@...gle.com>
To:     Namhyung Kim <namhyung@...nel.org>
Cc:     Arnaldo Carvalho de Melo <acme@...nel.org>,
        Jiri Olsa <jolsa@...nel.org>, Ingo Molnar <mingo@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        LKML <linux-kernel@...r.kernel.org>,
        Adrian Hunter <adrian.hunter@...el.com>,
        linux-perf-users@...r.kernel.org,
        Kan Liang <kan.liang@...ux.intel.com>,
        Zhengjun Xing <zhengjun.xing@...ux.intel.com>,
        James Clark <james.clark@....com>,
        Athira Jajeev <atrajeev@...ux.vnet.ibm.com>
Subject: Re: [PATCH 04/15] perf stat: Use scnprintf() in prepare_interval()

On Wed, Nov 23, 2022 at 10:02 AM Namhyung Kim <namhyung@...nel.org> wrote:
>
> It should not use sprintf() anymore.  Let's pass the buffer size and use the
> safer scnprintf() instead.
>
> Signed-off-by: Namhyung Kim <namhyung@...nel.org>

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

Thanks,
Ian

> ---
>  tools/perf/util/stat-display.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
> index 15c88b9b5aa3..744b7a40f59a 100644
> --- a/tools/perf/util/stat-display.c
> +++ b/tools/perf/util/stat-display.c
> @@ -1073,23 +1073,23 @@ static void print_metric_headers(struct perf_stat_config *config,
>  }
>
>  static void prepare_interval(struct perf_stat_config *config,
> -                            char *prefix, struct timespec *ts)
> +                            char *prefix, size_t len, struct timespec *ts)
>  {
>         if (config->iostat_run)
>                 return;
>
>         if (config->csv_output)
> -               sprintf(prefix, "%lu.%09lu%s", (unsigned long) ts->tv_sec,
> -                                ts->tv_nsec, config->csv_sep);
> +               scnprintf(prefix, len, "%lu.%09lu%s",
> +                         (unsigned long) ts->tv_sec, ts->tv_nsec, config->csv_sep);
>         else if (!config->json_output)
> -               sprintf(prefix, "%6lu.%09lu ", (unsigned long) ts->tv_sec,
> -                                ts->tv_nsec);
> +               scnprintf(prefix, len, "%6lu.%09lu ",
> +                         (unsigned long) ts->tv_sec, ts->tv_nsec);
>         else if (!config->metric_only)
> -               sprintf(prefix, "{\"interval\" : %lu.%09lu, ", (unsigned long)
> -                                ts->tv_sec, ts->tv_nsec);
> +               scnprintf(prefix, len, "{\"interval\" : %lu.%09lu, ",
> +                         (unsigned long) ts->tv_sec, ts->tv_nsec);
>         else
> -               sprintf(prefix, "{\"interval\" : %lu.%09lu}", (unsigned long)
> -                                ts->tv_sec, ts->tv_nsec);
> +               scnprintf(prefix, len, "{\"interval\" : %lu.%09lu}",
> +                         (unsigned long) ts->tv_sec, ts->tv_nsec);
>  }
>
>  static void print_header_interval_std(struct perf_stat_config *config,
> @@ -1390,7 +1390,7 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf
>
>         if (interval) {
>                 prefix = buf;
> -               prepare_interval(config, prefix, ts);
> +               prepare_interval(config, buf, sizeof(buf), ts);
>         }
>
>         print_header(config, _target, evlist, argc, argv);
> --
> 2.38.1.584.g0f3c55d4c2-goog
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ