Patchwork UBI: Fix check on unsigned in ytes_str_to_int()

login
register
mail settings
Submitter roel kluin
Date Oct. 16, 2009, noon
Message ID <4AD86051.2040302@gmail.com>
Download mbox | patch
Permalink /patch/36197/
State New
Headers show

Comments

roel kluin - Oct. 16, 2009, noon
result is unsigned, the wrong check was used.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
Artem Bityutskiy - Oct. 20, 2009, 7:20 a.m.
On Fri, 2009-10-16 at 14:00 +0200, Roel Kluin wrote:
> result is unsigned, the wrong check was used.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
> index e1f7d0a..14cec04 100644
> --- a/drivers/mtd/ubi/build.c
> +++ b/drivers/mtd/ubi/build.c
> @@ -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;

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

Patch

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index e1f7d0a..14cec04 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -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;