lkml.org 
[lkml]   [2013]   [Oct]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] core: Catch overflows in do_div() function
From
Date
On Tue, 2013-10-08 at 09:10 -0700, Anatol Pomozov wrote:
> If second parameter passed to this function was 64 then it silently
> truncates to 32 bits. Catch such situation.
>
> Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com>
> ---
> include/asm-generic/div64.h | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/include/asm-generic/div64.h b/include/asm-generic/div64.h
> index 8f4e319..84339a0 100644
> --- a/include/asm-generic/div64.h
> +++ b/include/asm-generic/div64.h
> @@ -17,6 +17,7 @@
> * beware of side effects!
> */
>
> +#include <linux/bug.h>
> #include <linux/types.h>
> #include <linux/compiler.h>
>
> @@ -25,6 +26,7 @@
> # define do_div(n,base) ({ \
> uint32_t __base = (base); \
> uint32_t __rem; \
> + BUG_ON(sizeof(base) > 4 && base >= (1UL<<32)); \

Problem is about

uint32_t __base = (base);

This was designed to avoid "base" being evaluated twice, as in

do_div(X, ++Y);

So I guess you need something to keep this in place.






\
 
 \ /
  Last update: 2013-10-08 20:01    [W:0.091 / U:0.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site