Re: [PATCH v1 02/10] perf, tools, stat: Avoid memory overrun with -r
From: Andi Kleen
Date: Mon Mar 11 2019 - 16:28:52 EST
On Mon, Mar 11, 2019 at 01:24:38PM -0700, Andi Kleen wrote:
> From: Andi Kleen <ak@xxxxxxxxxxxxxxx>
>
> When -r is used memory would get corrupted because the evsel->id array
> would get overrun. evsel->ids is a running counter of the last id.
> Normally this works fine, but with -r the same event is initialized
> multiple times, but not this counter, so it would keep growing
> beyond the array limit and corrupt random memory.
>
> Always reinitialize ->ids, and also add an assert to catch
> such overruns in the future.
>
> This fixes a perf segfault when running it from toplev.
This one should be Cc: stable
-Andi