All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched: fix string comparison in features
@ 2010-09-11 17:44 Mathieu Desnoyers
  2010-09-13 21:34 ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Mathieu Desnoyers @ 2010-09-11 17:44 UTC (permalink / raw)
  To: LKML, Peter Zijlstra
  Cc: Ingo Molnar, Steven Rostedt, Mathieu Desnoyers, Tony Lindgren

Incorrect handling of the following case:

INTERACTIVE
INTERACTIVE_SOMETHING_ELSE

The comparison only checks up to each element's length.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
---
 kernel/sched.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Index: linux-2.6-lttng.git/kernel/sched.c
===================================================================
--- linux-2.6-lttng.git.orig/kernel/sched.c
+++ linux-2.6-lttng.git/kernel/sched.c
@@ -722,7 +722,7 @@ sched_feat_write(struct file *filp, cons
 {
 	char buf[64];
 	char *cmp = buf;
-	int neg = 0;
+	int neg = 0, cmplen;
 	int i;
 
 	if (cnt > 63)
@@ -732,15 +732,24 @@ sched_feat_write(struct file *filp, cons
 		return -EFAULT;
 
 	buf[cnt] = 0;
+	for (i = 0; i < cnt; i++) {
+		if (buf[i] == '\n' || buf[i] == ' ') {
+			buf[i] = 0;
+			break;
+		}
+	}
 
 	if (strncmp(buf, "NO_", 3) == 0) {
 		neg = 1;
 		cmp += 3;
 	}
 
+	cmplen = strlen(cmp);
 	for (i = 0; sched_feat_names[i]; i++) {
 		int len = strlen(sched_feat_names[i]);
 
+		if (cmplen != len)
+			continue;
 		if (strncmp(cmp, sched_feat_names[i], len) == 0) {
 			if (neg)
 				sysctl_sched_features &= ~(1UL << i);
-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] sched: fix string comparison in features
  2010-09-11 17:44 [PATCH] sched: fix string comparison in features Mathieu Desnoyers
@ 2010-09-13 21:34 ` Steven Rostedt
  2010-09-13 21:40   ` Mathieu Desnoyers
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2010-09-13 21:34 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: LKML, Peter Zijlstra, Ingo Molnar, Tony Lindgren

On Sat, 2010-09-11 at 13:44 -0400, Mathieu Desnoyers wrote:
> Incorrect handling of the following case:
> 
> INTERACTIVE
> INTERACTIVE_SOMETHING_ELSE
> 
> The comparison only checks up to each element's length.

Replace all your changes with mine, and you have the same effect ;-)

-- Steve

> 
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> ---
>  kernel/sched.c |   11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> Index: linux-2.6-lttng.git/kernel/sched.c
> ===================================================================
> --- linux-2.6-lttng.git.orig/kernel/sched.c
> +++ linux-2.6-lttng.git/kernel/sched.c
> @@ -722,7 +722,7 @@ sched_feat_write(struct file *filp, cons
>  {
>  	char buf[64];
>  	char *cmp = buf;

-	char *cmp = buf;
+	char *cmp;

> -	int neg = 0;
> +	int neg = 0, cmplen;
>  	int i;
>  
>  	if (cnt > 63)
> @@ -732,15 +732,24 @@ sched_feat_write(struct file *filp, cons
>  		return -EFAULT;
>  
>  	buf[cnt] = 0;
> +	for (i = 0; i < cnt; i++) {
> +		if (buf[i] == '\n' || buf[i] == ' ') {
> +			buf[i] = 0;
> +			break;
> +		}
> +	}

+	cmp = strstrip(buf);

>  
>  	if (strncmp(buf, "NO_", 3) == 0) {
>  		neg = 1;
>  		cmp += 3;
>  	}
>  
> +	cmplen = strlen(cmp);
>  	for (i = 0; sched_feat_names[i]; i++) {
>  		int len = strlen(sched_feat_names[i]);

-		int len = strlen(sched_feat_names[i]);

>  
> +		if (cmplen != len)
> +			continue;
>  		if (strncmp(cmp, sched_feat_names[i], len) == 0) {

-		if (strncmp(cmp, sched_feat_names[i], len) == 0) {
+		if (strcmp(cmp, sched_feat_names[i]) == 0) {

>  			if (neg)
>  				sysctl_sched_features &= ~(1UL << i);



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] sched: fix string comparison in features
  2010-09-13 21:34 ` Steven Rostedt
@ 2010-09-13 21:40   ` Mathieu Desnoyers
  0 siblings, 0 replies; 3+ messages in thread
From: Mathieu Desnoyers @ 2010-09-13 21:40 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, Peter Zijlstra, Ingo Molnar, Tony Lindgren

* Steven Rostedt (rostedt@goodmis.org) wrote:
> On Sat, 2010-09-11 at 13:44 -0400, Mathieu Desnoyers wrote:
> > Incorrect handling of the following case:
> > 
> > INTERACTIVE
> > INTERACTIVE_SOMETHING_ELSE
> > 
> > The comparison only checks up to each element's length.
> 
> Replace all your changes with mine, and you have the same effect ;-)

Indeed, your approach looks much nicer. Will update.

Thanks,

Mathieu

> 
> -- Steve
> 
> > 
> > Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> > ---
> >  kernel/sched.c |   11 ++++++++++-
> >  1 file changed, 10 insertions(+), 1 deletion(-)
> > 
> > Index: linux-2.6-lttng.git/kernel/sched.c
> > ===================================================================
> > --- linux-2.6-lttng.git.orig/kernel/sched.c
> > +++ linux-2.6-lttng.git/kernel/sched.c
> > @@ -722,7 +722,7 @@ sched_feat_write(struct file *filp, cons
> >  {
> >  	char buf[64];
> >  	char *cmp = buf;
> 
> -	char *cmp = buf;
> +	char *cmp;
> 
> > -	int neg = 0;
> > +	int neg = 0, cmplen;
> >  	int i;
> >  
> >  	if (cnt > 63)
> > @@ -732,15 +732,24 @@ sched_feat_write(struct file *filp, cons
> >  		return -EFAULT;
> >  
> >  	buf[cnt] = 0;
> > +	for (i = 0; i < cnt; i++) {
> > +		if (buf[i] == '\n' || buf[i] == ' ') {
> > +			buf[i] = 0;
> > +			break;
> > +		}
> > +	}
> 
> +	cmp = strstrip(buf);
> 
> >  
> >  	if (strncmp(buf, "NO_", 3) == 0) {
> >  		neg = 1;
> >  		cmp += 3;
> >  	}
> >  
> > +	cmplen = strlen(cmp);
> >  	for (i = 0; sched_feat_names[i]; i++) {
> >  		int len = strlen(sched_feat_names[i]);
> 
> -		int len = strlen(sched_feat_names[i]);
> 
> >  
> > +		if (cmplen != len)
> > +			continue;
> >  		if (strncmp(cmp, sched_feat_names[i], len) == 0) {
> 
> -		if (strncmp(cmp, sched_feat_names[i], len) == 0) {
> +		if (strcmp(cmp, sched_feat_names[i]) == 0) {
> 
> >  			if (neg)
> >  				sysctl_sched_features &= ~(1UL << i);
> 
> 

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-09-13 21:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-11 17:44 [PATCH] sched: fix string comparison in features Mathieu Desnoyers
2010-09-13 21:34 ` Steven Rostedt
2010-09-13 21:40   ` Mathieu Desnoyers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.