2014-10-01 19:16:33

by Stephane Eranian

[permalink] [raw]
Subject: [BUG] perf tools: off-by-one error in map_groups__find_ams()

Hi,

It appears that there is a off-by-one bug in map_groups__find_ams().
The upper-bound check in the test below should be >= because
end = start + len; The end address is outside the range.

Please confirm.


int map_groups__find_ams(struct addr_map_symbol *ams, symbol_filter_t filter)
{
if (ams->addr < ams->map->start || ams->addr > ams->map->end) {


2014-10-02 08:37:15

by Jiri Olsa

[permalink] [raw]
Subject: Re: [BUG] perf tools: off-by-one error in map_groups__find_ams()

On Wed, Oct 01, 2014 at 09:16:31PM +0200, Stephane Eranian wrote:
> Hi,
>
> It appears that there is a off-by-one bug in map_groups__find_ams().
> The upper-bound check in the test below should be >= because
> end = start + len; The end address is outside the range.
>
> Please confirm.
>
>
> int map_groups__find_ams(struct addr_map_symbol *ams, symbol_filter_t filter)
> {
> if (ams->addr < ams->map->start || ams->addr > ams->map->end) {

yep, looks like bug to me

jirka

2014-10-02 16:40:21

by Stephane Eranian

[permalink] [raw]
Subject: Re: [BUG] perf tools: off-by-one error in map_groups__find_ams()

On Thu, Oct 2, 2014 at 10:36 AM, Jiri Olsa <[email protected]> wrote:
> On Wed, Oct 01, 2014 at 09:16:31PM +0200, Stephane Eranian wrote:
>> Hi,
>>
>> It appears that there is a off-by-one bug in map_groups__find_ams().
>> The upper-bound check in the test below should be >= because
>> end = start + len; The end address is outside the range.
>>
>> Please confirm.
>>
>>
>> int map_groups__find_ams(struct addr_map_symbol *ams, symbol_filter_t filter)
>> {
>> if (ams->addr < ams->map->start || ams->addr > ams->map->end) {
>
> yep, looks like bug to me
>
Are you providing a fix or should I?

2014-10-03 08:10:00

by Jiri Olsa

[permalink] [raw]
Subject: Re: [BUG] perf tools: off-by-one error in map_groups__find_ams()

On Thu, Oct 02, 2014 at 06:40:14PM +0200, Stephane Eranian wrote:
> On Thu, Oct 2, 2014 at 10:36 AM, Jiri Olsa <[email protected]> wrote:
> > On Wed, Oct 01, 2014 at 09:16:31PM +0200, Stephane Eranian wrote:
> >> Hi,
> >>
> >> It appears that there is a off-by-one bug in map_groups__find_ams().
> >> The upper-bound check in the test below should be >= because
> >> end = start + len; The end address is outside the range.
> >>
> >> Please confirm.
> >>
> >>
> >> int map_groups__find_ams(struct addr_map_symbol *ams, symbol_filter_t filter)
> >> {
> >> if (ams->addr < ams->map->start || ams->addr > ams->map->end) {
> >
> > yep, looks like bug to me
> >
> Are you providing a fix or should I?

please go ahead

jirka

2014-10-03 10:07:18

by Stephane Eranian

[permalink] [raw]
Subject: Re: [BUG] perf tools: off-by-one error in map_groups__find_ams()

On Fri, Oct 3, 2014 at 10:09 AM, Jiri Olsa <[email protected]> wrote:
> On Thu, Oct 02, 2014 at 06:40:14PM +0200, Stephane Eranian wrote:
>> On Thu, Oct 2, 2014 at 10:36 AM, Jiri Olsa <[email protected]> wrote:
>> > On Wed, Oct 01, 2014 at 09:16:31PM +0200, Stephane Eranian wrote:
>> >> Hi,
>> >>
>> >> It appears that there is a off-by-one bug in map_groups__find_ams().
>> >> The upper-bound check in the test below should be >= because
>> >> end = start + len; The end address is outside the range.
>> >>
>> >> Please confirm.
>> >>
>> >>
>> >> int map_groups__find_ams(struct addr_map_symbol *ams, symbol_filter_t filter)
>> >> {
>> >> if (ams->addr < ams->map->start || ams->addr > ams->map->end) {
>> >
>> > yep, looks like bug to me
>> >
>> Are you providing a fix or should I?
>
> please go ahead
>
Based on the same reasoning, I am wondering about the following too:

util/map.c:
int map_groups__fixup_overlappings()
{

after->start = map->end + 1;
^^^ should not be there
}
The first byte after a map is at map->end. Range if [start;end[