lkml.org 
[lkml]   [2015]   [Feb]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] lib/kstrtox.c Stop parsing integer on overflow
Date
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


\
 
 \ /
  Last update: 2015-02-16 20:21    [W:0.053 / U:0.140 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site