public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: "Martin Liška" <mliska@suse.cz>, dwz@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>, Jakub Jelinek <jakub@redhat.com>
Subject: Re: [PATCH] Fix UBSAN reported for Libreoffice so files.
Date: Mon, 15 Mar 2021 11:20:10 +0100	[thread overview]
Message-ID: <5c00bcd8-ed86-3b90-5e32-90dba3f80b7c@suse.de> (raw)
In-Reply-To: <7100560d-5973-8d34-c486-187c7dda21af@suse.cz>

[-- Attachment #1: Type: text/plain, Size: 101 bytes --]

On 3/15/21 8:48 AM, Martin Liška wrote:

Thanks for the patch, committed as attached.

Thanks,
- Tom

[-- Attachment #2: 0001-Fix-UBSAN-reported-for-Libreoffice-so-files.patch --]
[-- Type: text/x-patch, Size: 1967 bytes --]

Fix UBSAN reported for Libreoffice so files

Use 1U in left shifts in bitvector_set_bit and bitvector_bit_p to avoid
undefined signed left-shift behaviour.

Fixes:

dwz.c:9041:28: runtime error: left shift of 1 by 31 places cannot be \
  represented in type 'int'
     #0 0x405ad3 in bitvector_bit_p dwz.c:9041
     #1 0x405ad3 in create_import_tree dwz.c:9528
     #2 0x405ad3 in dwz dwz.c:15445
     #3 0x407517 in dwz_files dwz.c:16871
     #4 0x407517 in main dwz.c:16985
     #5 0x7ffff6a8eb24 in __libc_start_main ../csu/libc-start.c:332
     #6 0x4086dd in _start (dwz+0x4086dd)

dwz.c:9032:21: runtime error: left shift of 1 by 31 places cannot be \
  represented in type 'int'
     #0 0x405a83 in bitvector_set_bit dwz.c:9032
     #1 0x405a83 in create_import_tree dwz.c:9530
     #2 0x405a83 in dwz dwz.c:15445
     #3 0x407517 in dwz_files dwz.c:16871
     #4 0x407517 in main dwz.c:16985
     #5 0x7ffff6a8eb24 in __libc_start_main ../csu/libc-start.c:332
     #6 0x4086dd in _start (dwz+0x4086dd)

2021-03-15  Martin Liska  <mliska@suse.cz>

	* dwz.c (bitvector_set_bit, bitvector_bit_p): Use 1U in
	left shift to avoid undefined signed left-shift behaviour.

---
 dwz.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/dwz.c b/dwz.c
index cd06dc6..d41e26e 100644
--- a/dwz.c
+++ b/dwz.c
@@ -9029,7 +9029,7 @@ bitvector_set_bit (BITVECTOR_TYPE *vector, unsigned idx)
 {
   unsigned div = idx / (sizeof (BITVECTOR_TYPE) * 8);
   unsigned mod = idx % (sizeof (BITVECTOR_TYPE) * 8);
-  vector[div] |= (1 << mod);
+  vector[div] |= (1U << mod);
 }
 
 /* Test bit IDX in bitvector VECTOR.  */
@@ -9038,7 +9038,7 @@ bitvector_bit_p (BITVECTOR_TYPE *vector, unsigned idx)
 {
   unsigned div = idx / (sizeof (BITVECTOR_TYPE) * 8);
   unsigned mod = idx % (sizeof (BITVECTOR_TYPE) * 8);
-  return (vector[div] & (1 << mod)) != 0;
+  return (vector[div] & (1U << mod)) != 0;
 }
 
 /* Clear at least bits [A, B] in VECTOR, possibly more.  */

      reply	other threads:[~2021-03-15 10:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15  7:48 Martin Liška
2021-03-15 10:20 ` Tom de Vries [this message]

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=5c00bcd8-ed86-3b90-5e32-90dba3f80b7c@suse.de \
    --to=tdevries@suse.de \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    --cc=mark@klomp.org \
    --cc=mliska@suse.cz \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).