All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/kstrtox.c Stop parsing integer on overflow
@ 2015-01-22 13:58 Anshul Garg
  0 siblings, 0 replies; 3+ messages in thread
From: Anshul Garg @ 2015-01-22 13:58 UTC (permalink / raw)
  To: akpm, levex, felipe.contreras, linux-kernel; +Cc: aksgarg1989, anshul.g

From: Anshul Garg <aksgarg1989@gmail.com>

While converting string representation to integer
break the loop if overflow is detected.

Signed-off-by: Anshul Garg <aksgarg1989@gmail.com>
---
 lib/kstrtox.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index ec8da78..6f30209 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -70,8 +70,10 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long
 		 * it in the max base we support (16)
 		 */
 		if (unlikely(res & (~0ull << 60))) {
-			if (res > div_u64(ULLONG_MAX - val, base))
+			if (res > div_u64(ULLONG_MAX - val, base)) {
 				overflow = 1;
+				break;
+			}
 		}
 		res = res * base + val;
 		rv++;
-- 
1.7.9.5


---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com


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

* Re: [PATCH] lib/kstrtox.c Stop parsing integer on overflow
  2015-02-16 18:48 Anshul Garg
@ 2015-02-17 23:20 ` Richard Weinberger
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Weinberger @ 2015-02-17 23:20 UTC (permalink / raw)
  To: Anshul Garg; +Cc: LKML, anshul.g, Linus Torvalds

On Mon, Feb 16, 2015 at 7:48 PM, Anshul Garg <aksgarg1989@gmail.com> wrote:
> From: Anshul Garg <aksgarg1989@gmail.com>
>
> While converting string representation to integer
> break the loop if overflow is detected.
>
> Signed-off-by: Anshul Garg <aksgarg1989@gmail.com>
> ---
>  lib/kstrtox.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/lib/kstrtox.c b/lib/kstrtox.c
> index ec8da78..6f30209 100644
> --- a/lib/kstrtox.c
> +++ b/lib/kstrtox.c
> @@ -70,8 +70,10 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long
>                  * it in the max base we support (16)
>                  */
>                 if (unlikely(res & (~0ull << 60))) {
> -                       if (res > div_u64(ULLONG_MAX - val, base))
> +                       if (res > div_u64(ULLONG_MAX - val, base)) {
>                                 overflow = 1;
> +                               break;

This changes the behaviour as described at the function description.
Did you double check that all users of that function can deal with that?

> +                       }
>                 }
>                 res = res * base + val;
>                 rv++;
> --
> 1.7.9.5
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> http://www.avast.com
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/



-- 
Thanks,
//richard

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

* [PATCH] lib/kstrtox.c Stop parsing integer on overflow
@ 2015-02-16 18:48 Anshul Garg
  2015-02-17 23:20 ` Richard Weinberger
  0 siblings, 1 reply; 3+ messages in thread
From: Anshul Garg @ 2015-02-16 18:48 UTC (permalink / raw)
  To: linux-kernel; +Cc: aksgarg1989, anshul.g, torvalds

From: Anshul Garg <aksgarg1989@gmail.com>

While converting string representation to integer
break the loop if overflow is detected.

Signed-off-by: Anshul Garg <aksgarg1989@gmail.com>
---
 lib/kstrtox.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index ec8da78..6f30209 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -70,8 +70,10 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long
 		 * it in the max base we support (16)
 		 */
 		if (unlikely(res & (~0ull << 60))) {
-			if (res > div_u64(ULLONG_MAX - val, base))
+			if (res > div_u64(ULLONG_MAX - val, base)) {
 				overflow = 1;
+				break;
+			}
 		}
 		res = res * base + val;
 		rv++;
-- 
1.7.9.5


---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com


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

end of thread, other threads:[~2015-02-17 23:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-22 13:58 [PATCH] lib/kstrtox.c Stop parsing integer on overflow Anshul Garg
2015-02-16 18:48 Anshul Garg
2015-02-17 23:20 ` Richard Weinberger

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.