Skip to contentSkip to conversation

batman-adv: fix compat macro for kstrtou32

PATCH Applied Antonio Quartulli 2 participants 2 messages Nov 22, 2013 – Nov 23, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 batman-adv: fix compat macro for kstrtou32

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.

---
 compat.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
compat.h +10 -2
index a050bb8..6daeff9 100644
@@ -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
 
Signature · 1 line
1.8.4.4
#1 lore raw
Quoted 7 lines · On Friday 22 November 2013 18:38:30 Antonio Quartulli wrote:

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.

Quoted 8 lines

Possibly return -ERANGE is the result is too big to fix a 32bit long variable.

---
 compat.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Applied in revision 28dab26.

Thanks,
Marek