Fix UB in choose_service_fd_base due to calling __builtin_clz(0)

Submitted by Radoslaw Burny on April 9, 2018, 4:24 p.m.

Details

Message ID CAFkxGoPvsGcuYANoYWCmua_DGFOhchmTimX-Lq2KJPxoepSq_g@mail.gmail.com
State Accepted
Series "Fix UB in choose_service_fd_base due to calling __builtin_clz(0)"
Headers show

Commit Message

Radoslaw Burny April 9, 2018, 4:24 p.m.
It seems like patchwork is picking up the patches, but it's unhappy with
the formatted corruption caused by my Vim config
(basically, tabs were rendered as spaces and caused merge conflicts when
included in the patch).
Let me try one last time before I'm banned from this mailing list for spam
:)



From: Radoslaw Burny <rburny at google.com>

Subject: [PATCH] Fix UB in choose_service_fd_base.

Signed-off-by: Radoslaw Burny <rburny at google.com>

---
 criu/util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

  /* Right border is bigger, than rlim. OK, then just aligned value is
enough */

Patch hide | download patch | download mbox

diff --git a/criu/util.c b/criu/util.c
index b19bf517..48ba09a8 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -588,9 +588,9 @@  static int choose_service_fd_base(struct pstree_item
*me)
  nr += 16; /* Safety pad */
  real_nr = nr;

- nr /= (1024 / sizeof(void *));
+ /* Align nr to the power of 2 for easier debugging */
+ BUG_ON(nr <= 0);
  nr = 1 << (32 - __builtin_clz(nr));
- nr *= (1024 / sizeof(void *));

  if (nr > service_fd_rlim_cur) {