Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: krokus <nomadbyte@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] Undefined behavior reported in copy_bitwise
Date: Thu, 9 Apr 2020 18:50:58 -0500	[thread overview]
Message-ID: <CAMCMYR5=V6WBN-AZw4R8EAVxkRt4T62G0JCARAaCc77PiwF7LQ@mail.gmail.com> (raw)

gdb version 9.1, built with clang 8.0.0 on Ubuntu 18.04 (x86_64);
--enable-ubsan (for clang's undefined behavior sanitizer)

Executing command; `maint selftest copy_bitwise` bombs in runtime error:
../../gdb/utils.c:3432:28: runtime error: left shift of negative value -1

Closer look reveals the offending shift: `(~0 << nbits)`, apparently 0
is treated as signed int, resulting in negative complement. Explicitly
stating it unsigned 0U  fixes it and the `copy_bitwise` test passes
ok.

patch -p1:
````````
--- gdb/utils.c    2020-04-09 18:41:03.339065535 -0500
+++ gdb/utils.c    2020-04-09 18:41:24.427064851 -0500
@@ -3429,7 +3429,7 @@
     buf |= *source << avail;

       buf &= (1 << nbits) - 1;
-      *dest = (*dest & (~0 << nbits)) | buf;
+      *dest = (*dest & (~0U << nbits)) | buf;
     }
 }
````````


             reply	other threads:[~2020-04-09 23:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09 23:50 krokus [this message]
2020-04-10 14:59 ` Simon Marchi
2020-04-10 20:56   ` krokus
2020-04-10 21:24     ` Simon Marchi
2020-04-11  1:08       ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMCMYR5=V6WBN-AZw4R8EAVxkRt4T62G0JCARAaCc77PiwF7LQ@mail.gmail.com' \
    --to=nomadbyte@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox