Skip to contentSkip to conversation

UBI: Fix check on unsigned in ytes_str_to_int()

PATCH Applied Roel Kluin 2 participants 2 messages Oct 16, 2009 – Oct 20, 2009

Subsystems (2)
lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 UBI: Fix check on unsigned in ytes_str_to_int()

result is unsigned, the wrong check was used.

---

drivers/mtd/ubi/build.c +2 -1
index e1f7d0a..14cec04 100644
@@ -42,6 +42,7 @@
 #include <linux/log2.h>
 #include <linux/kthread.h>
 #include <linux/reboot.h>
+#include <linux/kernel.h>
 #include "ubi.h"
 
 /* Maximum length of the 'mtd=' parameter */
@@ -1257,7 +1258,7 @@ static int __init bytes_str_to_int(const char *str)
 	unsigned long result;
 
 	result = simple_strtoul(str, &endp, 0);
-	if (str == endp || result < 0) {
+	if (str == endp || result >= INT_MAX) {
 		printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
 		       str);
 		return -EINVAL;
#1 lore raw
Quoted 17 lines · Roel Kluin

result is unsigned, the wrong check was used.

---

drivers/mtd/ubi/build.c +1 -0
index e1f7d0a..14cec04 100644
@@ -42,6 +42,7 @@
 #include <linux/log2.h>
 #include <linux/kthread.h>
 #include <linux/reboot.h>
+#include <linux/kernel.h>
 #include "ubi.h"
 
 /* Maximum length of the 'mtd=' parameter */

drivers/mtd/ubi/build.c static int __init bytes_str_to_int(const char *str) · line 1264

Quoted 8 lines
drivers/mtd/ubi/build.c +1 -1
@@ -1257,7 +1258,7 @@ static int __init bytes_str_to_int(const char *str)
 	unsigned long result;
 
 	result = simple_strtoul(str, &endp, 0);
-	if (str == endp || result < 0) {
+	if (str == endp || result >= INT_MAX) {
 		printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
 		       str);
 		return -EINVAL;

Pushed to ubi-2.6 tree, will send to Linus soon, thanks.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)