[PATCH 1/3] libdw: Make srclines use a stable sort

Josh Stone jistone at redhat.com
Fri Dec 12 01:34:06 UTC 2014


BTW, I want to point out this change in compare_lines:

> -  return (*p1)->addr - (*p2)->addr;
[...]
> +  if (line1->addr != line2->addr)
> +    return (line1->addr < line2->addr) ? -1 : 1;

Since addr is 64-bit unsigned, and comparison functions return int, it
is possible for the difference to be so large that it wraps around.  You
only need INT_MAX or more -- which probably doesn't happen often in ELF
files, but it's plausible.

It might be worth auditing other qsort/tsearch comparison functions for
similar wrapping possibilities.


More information about the elfutils-devel mailing list