Re: [PATCH] perf data convert: Output empty string for null pointer

From: Namhyung Kim
Date: Thu Jan 25 2024 - 18:31:45 EST


Hello,

On Thu, Jan 25, 2024 at 12:59 PM Ian Rogers <irogers@xxxxxxxxxx> wrote:
>
> On Thu, Jan 25, 2024 at 10:44 AM <kotborealis@xxxxxxxx> wrote:
> >
> > From: Evgeny Pistun <kotborealis@xxxxxxxx>
> >
> > Providing ill-formed input to `perf data conver --to-json`
> > causes it to crash with segmentaton fault. There's a bug in
> > `output_json_string` functon: input string is not validated.
> > This could be reproduced by crafting input that does not specify
> > hostname/os-release/etc, which are written to 'headers' section of
> > outputted json.
> >
> > This patch adds a null pointer check. If `output_json_string` is
> > called with a null pointer, it should output empty string (`""`).
> >
> > Signed-off-by: Evgeny Pistun <kotborealis@xxxxxxxx>
>
> Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>

I think this is related to this one:

https://lore.kernel.org/linux-perf-users/20240117215101.77713-1-ilkka@xxxxxxxxxxxxxxxxxxxxxx/

I'm ok with making it robust, but also afraid it might
end up with a broken JSON if something is missing in
{ key: value } format. IOW we may need to handle it in
a higher layer.

Thanks,
Namhyung