[PATCH] lib/util/idtree.c: fix undefined behaviour by using uint in left-shift

Jeremy Allison jra at samba.org
Thu Feb 25 19:31:40 UTC 2016


On Thu, Feb 25, 2016 at 04:43:39PM +0100, Aurélien Aptel wrote:
> Hi,
>     
> Using negative values (~0 with no suffix is signed and == -1) on the
> left-side of a left-shift operation is an Undefined Behaviour in C.
> 
> Please review&push

Good catch ! Revewied-by: Jeremy Allison <jra at samba.org>

Can I get a second Team reviewer ?

> -- 
> Aurélien Aptel / SUSE Labs Samba Team
> GPG: 1839 CB5F 9F5B FB9B AA97  8C99 03C8 A49B 521B D5D3
> SUSE Linux GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
> GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG
> Nürnberg)

> From f6e5d8b07e3a63b461e13ebe06b5897f5079c8ea Mon Sep 17 00:00:00 2001
> From: Aurelien Aptel <aaptel at suse.com>
> Date: Thu, 25 Feb 2016 13:58:01 +0100
> Subject: [PATCH 3/3] lib/util/idtree.c: fix UB by using uint in left-shift
> 
> Using negative values on the left-side of a left-shift operation is an
> Undefined Behaviour in C.
> 
> Signed-off-by: Aurelien Aptel <aaptel at suse.com>
> ---
>  lib/util/idtree.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/util/idtree.c b/lib/util/idtree.c
> index e2cfcc5..72266a6 100644
> --- a/lib/util/idtree.c
> +++ b/lib/util/idtree.c
> @@ -289,7 +289,7 @@ static void *_idr_find(struct idr_context *idp, int id)
>  	 * present.  If so, tain't one of ours!
>  	 */
>  	if (n + IDR_BITS < 31 &&
> -	    ((id & ~(~0 << MAX_ID_SHIFT)) >> (n + IDR_BITS))) {
> +	    ((id & ~(~0U << MAX_ID_SHIFT)) >> (n + IDR_BITS))) {
>  		return NULL;
>  	}
>  
> -- 
> 2.1.4
> 






More information about the samba-technical mailing list