Skip to contentSkip to conversation

sched: fix string comparison in features

PATCH In review Mathieu Desnoyers 2 participants 3 messages Sep 11, 2010 – Sep 13, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched: fix string comparison in features

Incorrect handling of the following case:

INTERACTIVE
INTERACTIVE_SOMETHING_ELSE

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

---
 kernel/sched.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
kernel/sched.c +10 -1
Index: 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);
Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
#1 lore raw
Quoted 6 lines · Mathieu Desnoyers

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

Quoted 11 lines
---
 kernel/sched.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Index: linux-2.6-lttng.git/kernel/sched.c
===================================================================

kernel/sched.c sched_feat_write(struct file *filp, cons · line 724

Quoted 3 lines
kernel/sched.c +0 -0
@@ -722,7 +722,7 @@ sched_feat_write(struct file *filp, cons
 {
 	char buf[64];
 	char *cmp = buf;

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

Quoted 6 lines
kernel/sched.c +1 -1
-	int neg = 0;
+	int neg = 0, cmplen;
 	int i;
 
 	if (cnt > 63)

kernel/sched.c sched_feat_write(struct file *filp, cons · line 740

Quoted 9 lines
kernel/sched.c +6 -0
@@ -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);

kernel/sched.c sched_feat_write(struct file *filp, cons · line 749

Quoted 9 lines
kernel/sched.c +1 -0
 	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]);

kernel/sched.c sched_feat_write(struct file *filp, cons · line 753

Quoted 4 lines
kernel/sched.c +2 -0
+		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) {

Quoted 2 lines
kernel/sched.c +0 -0
 			if (neg)
 				sysctl_sched_features &= ~(1UL << i);
#2 lore raw
Quoted 9 lines · * Steven Rostedt ([email protected]) wrote:
Quoted 6 lines · Mathieu Desnoyers

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

Quoted 63 lines

-- Steve

Quoted 14 lines
---
 kernel/sched.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Index: linux-2.6-lttng.git/kernel/sched.c
===================================================================

kernel/sched.c +0 -0
@@ -722,7 +722,7 @@ sched_feat_write(struct file *filp, cons
 {
 	char buf[64];
 	char *cmp = buf;
(quoted diff) +1 -1
-	char *cmp = buf;
+	char *cmp;
Quoted 16 lines
kernel/sched.c +7 -1
-	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;
+		}
+	}
(quoted diff) +1 -0
+	cmp = strstrip(buf);
Quoted 10 lines
kernel/sched.c +1 -0
 	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]);
(quoted diff) +0 -1
-		int len = strlen(sched_feat_names[i]);
Quoted 5 lines
kernel/sched.c +2 -0
+		if (cmplen != len)
+			continue;
 		if (strncmp(cmp, sched_feat_names[i], len) == 0) {
(quoted diff) +1 -1
-		if (strncmp(cmp, sched_feat_names[i], len) == 0) {
+		if (strcmp(cmp, sched_feat_names[i]) == 0) {
Quoted 3 lines
kernel/sched.c +0 -0
 			if (neg)
 				sysctl_sched_features &= ~(1UL << i);
Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com