On Thu, Jan 30, 2025 at 3:23 PM Ian Lance Taylor <i...@golang.org> wrote:
>
> This patch from pgerell at GitHub adds some casts to libbacktrace to
> avoid undefined shifts. These shifts are OK on all real systems but
> may as well get it right. Bootstrapped and ran libbacktrace tests on
> x86_64-pc-linux-gnu. Committed to mainline.

That patch had a bug, fixed by this patch, also from pgerell@github.
Bootstrapped and ran libbacktrace tests on x86_64-pc-linux-gnu.
Committed to mainline.

Ian

libbacktrace: add cast to avoid undefined shift

Patch from pgerell@github.

* elf.c (elf_uncompress_lzma_block): Add casts to avoid
potentially shifting a value farther than its type size.
d5c72da62d29cfa0fff532c66f28670c2dfcd75e
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index d766fa41a61..868d0e1a7f3 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -5878,7 +5878,7 @@ elf_uncompress_lzma_block (const unsigned char 
*compressed,
          /* The byte at compressed[off] is ignored for some
             reason.  */
 
-         code = ((uint32_t)(compressed[off + 1] << 24)
+         code = (((uint32_t)compressed[off + 1] << 24)
                  + ((uint32_t)compressed[off + 2] << 16)
                  + ((uint32_t)compressed[off + 3] << 8)
                  + (uint32_t)compressed[off + 4]);

Reply via email to