[CRIU] [PATCH] sfds: Fix UB in choose_service_fd_base due to calling __builtin_clz(0)
Andrei Vagin
avagin at virtuozzo.com
Thu Apr 19 23:38:26 MSK 2018
Applied, thanks!
On Tue, Apr 10, 2018 at 01:35:04PM +0300, Kirill Tkhai wrote:
> From: Radoslaw Burny <rburny at google.com>
>
> __builtin_clz(0) leads to undefined behaviour:
> https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
>
> Set nr = 1 directly to avoid this.
>
> Link: https://github.com/checkpoint-restore/criu/issues/470
> Signed-off-by: Radoslaw Burny <rburny at google.com>
> Acked-by: Kirill Tkhai <ktkhai at virtuozzo.com>
> ---
> criu/util.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/criu/util.c b/criu/util.c
> index b19bf5175..46d67eca6 100644
> --- a/criu/util.c
> +++ b/criu/util.c
> @@ -589,7 +589,10 @@ static int choose_service_fd_base(struct pstree_item *me)
> real_nr = nr;
>
> nr /= (1024 / sizeof(void *));
> - nr = 1 << (32 - __builtin_clz(nr));
> + if (nr)
> + nr = 1 << (32 - __builtin_clz(nr));
> + else
> + nr = 1;
> nr *= (1024 / sizeof(void *));
>
> if (nr > service_fd_rlim_cur) {
>
More information about the CRIU
mailing list