Commit 72d5e41a authored by Radoslaw Burny's avatar Radoslaw Burny Committed by Andrei Vagin

sfds: Fix UB in choose_service_fd_base due to calling __builtin_clz(0)

__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/470Signed-off-by: 's avatarRadoslaw Burny <rburny@google.com>
Acked-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent f872b431
...@@ -591,7 +591,10 @@ static int choose_service_fd_base(struct pstree_item *me) ...@@ -591,7 +591,10 @@ static int choose_service_fd_base(struct pstree_item *me)
real_nr = nr; real_nr = nr;
nr /= (1024 / sizeof(void *)); nr /= (1024 / sizeof(void *));
if (nr)
nr = 1 << (32 - __builtin_clz(nr)); nr = 1 << (32 - __builtin_clz(nr));
else
nr = 1;
nr *= (1024 / sizeof(void *)); nr *= (1024 / sizeof(void *));
if (nr > service_fd_rlim_cur) { if (nr > service_fd_rlim_cur) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment