• Ian Rogers's avatar
    libperf evsel: Make use of FD robust. · aba5daeb
    Ian Rogers authored
    FD uses xyarray__entry that may return NULL if an index is out of
    bounds. If NULL is returned then a segv happens as FD unconditionally
    dereferences the pointer. This was happening in a case of with perf
    iostat as shown below. The fix is to make FD an "int*" rather than an
    int and handle the NULL case as either invalid input or a closed fd.
    
      $ sudo gdb --args perf stat --iostat  list
      ...
      Breakpoint 1, perf_evsel__alloc_fd (evsel=0x5555560951a0, ncpus=1, nthreads=1) at evsel.c:50
      50      {
      (gdb) bt
       #0  perf_evsel__alloc_fd (evsel=0x5555560951a0, ncpus=1, nthreads=1) at evsel.c:50
       #1  0x000055555585c188 in evsel__open_cpu (evsel=0x5555560951a0, cpus=0x555556093410,
          threads=0x555556086fb0, start_cpu=0, end_cpu=1) at util/evsel.c:1792
       #2  0x000055555585cfb2 in evsel__open (evsel=0x5555560951a0, cpus=0x0, threads=0x555556086fb0)
          at util/evsel.c:2045
       #3  0x000055555585d0db in evsel__open_per_thread (evsel=0x5555560951a0, threads=0x555556086...
    aba5daeb
evsel.c 8.86 KB