* [B.A.T.M.A.N.] [PATCH] batman-adv: fix compat macro for kstrtou32
@ 2013-11-22 17:38 Antonio Quartulli
2013-11-23 16:45 ` Marek Lindner
0 siblings, 1 reply; 2+ messages in thread
From: Antonio Quartulli @ 2013-11-22 17:38 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Antonio Quartulli
The macro previously introduced in the compat code to replace
kstrtou32() may not work properly in case of a too large
user input.
Fix it by using a temporary variable of the proper length
and then cast the result.
Possibly return -ERANGE is the result is too big to fix a 32bit
long variable.
Cc: Matthias Schiffer <mschiffer@universe-factory.net>
Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>
---
compat.h | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/compat.h b/compat.h
index a050bb8..6daeff9 100644
--- a/compat.h
+++ b/compat.h
@@ -152,8 +152,16 @@ static inline int batadv_param_set_copystring(const char *val,
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39)
-/* cast last argument of strict_strtoul() because we have a uint32_t */
-#define kstrtou32(cp, base, v) strict_strtoul(cp, base, (unsigned long *)v)
+#define kstrtou32(cp, base, v)\
+({\
+ unsigned long _v;\
+ int _r;\
+ _r = strict_strtoul(cp, base, &_v);\
+ *(v) = (uint32_t)_v;\
+ if ((unsigned long)*(v) != _v)\
+ _r = -ERANGE;\
+ _r;\
+})
#define kstrtoul strict_strtoul
#define kstrtol strict_strtol
--
1.8.4.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-11-23 16:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-22 17:38 [B.A.T.M.A.N.] [PATCH] batman-adv: fix compat macro for kstrtou32 Antonio Quartulli
2013-11-23 16:45 ` Marek Lindner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox