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: <CAP-5=fWxxaL7xqTFmButfVUEBCXB9PQOVovooMq+Z7NqP=10HA@mail.gmail.com>
Date:   Mon, 14 Aug 2023 13:24:06 -0700
From:   Ian Rogers <irogers@...gle.com>
To:     Kaige Ye <ye@...ge.org>
Cc:     peterz@...radead.org, mingo@...hat.com, acme@...nel.org,
        mark.rutland@....com, alexander.shishkin@...ux.intel.com,
        jolsa@...nel.org, namhyung@...nel.org, adrian.hunter@...el.com,
        linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] perf stat-display: Check if snprintf()'s fmt argument
 is NULL

On Thu, Aug 3, 2023 at 7:10 PM Kaige Ye <ye@...ge.org> wrote:
>
> It is undefined behavior to pass NULL as snprintf()'s fmt argument.
> Here is an example to trigger the problem:
>
>   $ perf stat --metric-only -x, -e instructions -- sleep 1
>   insn per cycle,
>   Segmentation fault (core dumped)
>
> With this patch:
>
>   $ perf stat --metric-only -x, -e instructions -- sleep 1
>   insn per cycle,
>   ,
>
> Signed-off-by: Kaige Ye <ye@...ge.org>

Thanks Kaige!

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

> ---
> V1 -> V2: Addressed Ian's comments (Ian Rogers)
> ---
>  tools/perf/util/stat-display.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
> index 7329b3340..031888545 100644
> --- a/tools/perf/util/stat-display.c
> +++ b/tools/perf/util/stat-display.c
> @@ -578,7 +578,7 @@ static void print_metric_only_csv(struct perf_stat_config *config __maybe_unused
>         if (!valid_only_metric(unit))
>                 return;
>         unit = fixunit(tbuf, os->evsel, unit);
> -       snprintf(buf, sizeof buf, fmt, val);
> +       snprintf(buf, sizeof(buf), fmt ?: "", val);
>         ends = vals = skip_spaces(buf);
>         while (isdigit(*ends) || *ends == '.')
>                 ends++;
> @@ -600,7 +600,7 @@ static void print_metric_only_json(struct perf_stat_config *config __maybe_unuse
>         if (!valid_only_metric(unit))
>                 return;
>         unit = fixunit(tbuf, os->evsel, unit);
> -       snprintf(buf, sizeof(buf), fmt, val);
> +       snprintf(buf, sizeof(buf), fmt ?: "", val);
>         ends = vals = skip_spaces(buf);
>         while (isdigit(*ends) || *ends == '.')
>                 ends++;
>
> base-commit: f6b8436bede3e80226e8b2100279c4450c73806a
> --
> 2.41.0
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ