Re: [PATCH v3 02/11] libtracefs: New APIs for dynamic events

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 3 Nov 2021 13:03:19 -0400
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> > +	address = strtok_r(NULL, " ", &sav);
> > +	if (!address)
> > +		address = event + strlen(event) + 1;
> > +	else
> > +		format = address + strlen(address) + 1;  
> 
> I'm not sure this is what you want to do, as the above is dangerous. If we
> have the following string:
> 
>   "p: system/event"
> 
> 	event + strlen(event) = '\0'
> 	event + strlen(event) + 1 = out-of-bounds;
> 
> Note, strtok_r() does not need to find the delimiter if the token is the
> last delimiter.
> 
> 	char str[] = "first last";
> 	char *a, *b, *s;
> 
> 	a = strtok_r(str, " ", &s);
> 	b = strtok_r(NULL, " ", &s);
> 
> Will result with: a = "first" and b = "last"

I'm guessing address is something you always expect? Then the above
really should be:

	address = strtok_r(NULL, " ", &sav);
	if (!address)
		return -1;

	format = strtok_r(NULL, "", @sav);

where format will get the rest of the string (if there is any), or be
NULL if there's nothing left.

-- Steve



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux