lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190726205544.yffnsfsnji362jk7@alap3.anarazel.de>
Date:   Fri, 26 Jul 2019 13:55:44 -0700
From:   Andres Freund <andres@...razel.de>
To:     Steven Rostedt <rostedt@...dmis.org>
Cc:     Arnaldo Carvalho de Melo <acme@...nel.org>,
        LKML <linux-kernel@...r.kernel.org>,
        Linux Trace Devel <linux-trace-devel@...r.kernel.org>,
        Tzvetomir Stoyanov <tstoyanov@...are.com>,
        Jiri Olsa <jolsa@...hat.com>, Ingo Molnar <mingo@...nel.org>,
        Namhyung Kim <namhyung@...nel.org>
Subject: Re: [PATCH] tools/lib/traceevent, tools/perf: Move struct
 tep_handler definition in a local header file

Hi,

On 2019-07-26 09:12:00 -0400, Steven Rostedt wrote:
> On Thu, 25 Jul 2019 20:58:29 -0700
> Andres Freund <andres@...razel.de> wrote:
> > 
> > Is just plain wrong, as:
> > 
> > > -		return pevent->events[idx];
> > > +		return (all_events + idx);  
> > 
> > that's not a valid conversion. ->events isn't an array of tep_handle,
> > it's an array of tep_handle* (and even if it were, the previous notation
> 
> You're right, it is wrong, but it's not tep_handle* but
> tep_event_format*.

Err, yea. Typo.



> > diff --git i/tools/lib/traceevent/event-parse.h w/tools/lib/traceevent/event-parse.h
> > index 642f68ab5fb2..7ebc9b5308d4 100644
> > --- i/tools/lib/traceevent/event-parse.h
> > +++ w/tools/lib/traceevent/event-parse.h
> > @@ -517,6 +517,7 @@ int tep_read_number_field(struct tep_format_field *field, const void *data,
> >  			  unsigned long long *value);
> >  
> >  struct tep_event *tep_get_first_event(struct tep_handle *tep);
> > +struct tep_event *tep_get_event(struct tep_handle *tep, int index);
> 
> I was looking at the tep_get_event() code, and we should switch that to
> "unsigned int index" otherwise passing in a negative number will return
> an address outside the array.

Makes sense.


> >  int tep_get_events_count(struct tep_handle *tep);
> >  struct tep_event *tep_find_event(struct tep_handle *tep, int id);
> >  
> > diff --git i/tools/perf/util/trace-event-parse.c w/tools/perf/util/trace-event-parse.c
> > index 62bc61155dd1..6a035ffd58ac 100644
> > --- i/tools/perf/util/trace-event-parse.c
> > +++ w/tools/perf/util/trace-event-parse.c
> > @@ -179,28 +179,26 @@ struct tep_event *trace_find_next_event(struct tep_handle *pevent,
> >  {
> >  	static int idx;
> >  	int events_count;
> > -	struct tep_event *all_events;
> >  
> > -	all_events = tep_get_first_event(pevent);
> >  	events_count = tep_get_events_count(pevent);
> 
> I think we can get rid of the events_count and all its checks, as the
> same check is done within tep_get_event().

> > -	if (!pevent || !all_events || events_count < 1)
> > +	if (!pevent || events_count < 1)
> 
> 	if (!pevent)
> 
> >  		return NULL;
> >  
> >  	if (!event) {
> >  		idx = 0;
> > -		return all_events;
> > +		return tep_get_event(pevent, 0);
> >  	}
> >  
> > -	if (idx < events_count && event == (all_events + idx)) {
> > +	if (idx < events_count && event == tep_get_event(pevent, idx)) {
> 
> 	if (event == tep_get_event(pevent, idx))
> 		return tep_get_event(pevent, ++idx);
> 
> >  		idx++;
> >  		if (idx == events_count)
> >  			return NULL;
> > -		return (all_events + idx);
> > +		return tep_get_event(pevent, idx);
> >  	}
> >  
> 
> 	struct tep_event_format *next_event;
> 
> 	for (idx = 0; next_event = tep_get_event(pevent, idx); idx++)
> 		if (event == next_event)
> 			return tep_get_event(pevent, ++idx);
> 
> Also, I think setting the idx to 1 in the loop is wrong. Why? think of
> this:
> 
> 	first_event = trace_find_next_event(pevent, NULL);
> 
> 	next_event = trace_find_next_event(pevent, first_event);
> 	for (i = 0; i < 5; i++)
> 		next_event = trace_find_next_event(pevent, next_event);
> 
> 	second_event = trace_find_next_event(pevent, first_event);
> 
> second_event would become NULL.

How about my proposal to instead change the loops in
trace-event-{python,perl}.c, the only callers of trace_find_next_event,
to be something akin to

[idx_type_for_tep_get_event] event_count = tep_get_events_count(pevent);
for ([idx_type_for_tep_get_event] idx = 0; idx < event_count; idx++)
{
	struct tep_event *event = tep_get_events(...);

}

and just removing trace_find_next_event()? It's not a nice API imo, and
seems unnecessary given that the events aren't a linked list anymore.


> Care to send a formal patch?

Will do.

Greetings,

Andres Freund

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ