mirror of
https://github.com/ianlancetaylor/libbacktrace.git
synced 2026-03-13 13:59:07 +08:00
libbacktrace: fix UBSAN issues
Fix issues mentioned in the PR. PR libbacktrace/103167 libbacktrace/ChangeLog: * elf.c (elf_uncompress_lzma_block): Cast to unsigned int. (elf_uncompress_lzma): Likewise. * xztest.c (test_samples): memcpy only if v > 0.
This commit is contained in:
committed by
Ian Lance Taylor
parent
c5cc931918
commit
5aa92540f0
32
elf.c
32
elf.c
@@ -5687,10 +5687,10 @@ elf_uncompress_lzma_block (const unsigned char *compressed,
|
|||||||
/* Block header CRC. */
|
/* Block header CRC. */
|
||||||
computed_crc = elf_crc32 (0, compressed + block_header_offset,
|
computed_crc = elf_crc32 (0, compressed + block_header_offset,
|
||||||
block_header_size - 4);
|
block_header_size - 4);
|
||||||
stream_crc = (compressed[off]
|
stream_crc = ((uint32_t)compressed[off]
|
||||||
| (compressed[off + 1] << 8)
|
| ((uint32_t)compressed[off + 1] << 8)
|
||||||
| (compressed[off + 2] << 16)
|
| ((uint32_t)compressed[off + 2] << 16)
|
||||||
| (compressed[off + 3] << 24));
|
| ((uint32_t)compressed[off + 3] << 24));
|
||||||
if (unlikely (computed_crc != stream_crc))
|
if (unlikely (computed_crc != stream_crc))
|
||||||
{
|
{
|
||||||
elf_uncompress_failed ();
|
elf_uncompress_failed ();
|
||||||
@@ -6300,10 +6300,10 @@ elf_uncompress_lzma (struct backtrace_state *state,
|
|||||||
|
|
||||||
/* Next comes a CRC of the stream flags. */
|
/* Next comes a CRC of the stream flags. */
|
||||||
computed_crc = elf_crc32 (0, compressed + 6, 2);
|
computed_crc = elf_crc32 (0, compressed + 6, 2);
|
||||||
stream_crc = (compressed[8]
|
stream_crc = ((uint32_t)compressed[8]
|
||||||
| (compressed[9] << 8)
|
| ((uint32_t)compressed[9] << 8)
|
||||||
| (compressed[10] << 16)
|
| ((uint32_t)compressed[10] << 16)
|
||||||
| (compressed[11] << 24));
|
| ((uint32_t)compressed[11] << 24));
|
||||||
if (unlikely (computed_crc != stream_crc))
|
if (unlikely (computed_crc != stream_crc))
|
||||||
{
|
{
|
||||||
elf_uncompress_failed ();
|
elf_uncompress_failed ();
|
||||||
@@ -6344,10 +6344,10 @@ elf_uncompress_lzma (struct backtrace_state *state,
|
|||||||
|
|
||||||
/* Before that is a footer CRC. */
|
/* Before that is a footer CRC. */
|
||||||
computed_crc = elf_crc32 (0, compressed + offset, 6);
|
computed_crc = elf_crc32 (0, compressed + offset, 6);
|
||||||
stream_crc = (compressed[offset - 4]
|
stream_crc = ((uint32_t)compressed[offset - 4]
|
||||||
| (compressed[offset - 3] << 8)
|
| ((uint32_t)compressed[offset - 3] << 8)
|
||||||
| (compressed[offset - 2] << 16)
|
| ((uint32_t)compressed[offset - 2] << 16)
|
||||||
| (compressed[offset - 1] << 24));
|
| ((uint32_t)compressed[offset - 1] << 24));
|
||||||
if (unlikely (computed_crc != stream_crc))
|
if (unlikely (computed_crc != stream_crc))
|
||||||
{
|
{
|
||||||
elf_uncompress_failed ();
|
elf_uncompress_failed ();
|
||||||
@@ -6403,10 +6403,10 @@ elf_uncompress_lzma (struct backtrace_state *state,
|
|||||||
/* Next is a CRC of the index. */
|
/* Next is a CRC of the index. */
|
||||||
computed_crc = elf_crc32 (0, compressed + index_offset,
|
computed_crc = elf_crc32 (0, compressed + index_offset,
|
||||||
offset - index_offset);
|
offset - index_offset);
|
||||||
stream_crc = (compressed[offset]
|
stream_crc = ((uint32_t)compressed[offset]
|
||||||
| (compressed[offset + 1] << 8)
|
| ((uint32_t)compressed[offset + 1] << 8)
|
||||||
| (compressed[offset + 2] << 16)
|
| ((uint32_t)compressed[offset + 2] << 16)
|
||||||
| (compressed[offset + 3] << 24));
|
| ((uint32_t)compressed[offset + 3] << 24));
|
||||||
if (unlikely (computed_crc != stream_crc))
|
if (unlikely (computed_crc != stream_crc))
|
||||||
{
|
{
|
||||||
elf_uncompress_failed ();
|
elf_uncompress_failed ();
|
||||||
|
|||||||
2
xztest.c
2
xztest.c
@@ -172,7 +172,7 @@ test_samples (struct backtrace_state *state)
|
|||||||
tests[i].name, uncompressed_len, v);
|
tests[i].name, uncompressed_len, v);
|
||||||
++failures;
|
++failures;
|
||||||
}
|
}
|
||||||
else if (memcmp (tests[i].uncompressed, uncompressed, v) != 0)
|
else if (v > 0 && memcmp (tests[i].uncompressed, uncompressed, v) != 0)
|
||||||
{
|
{
|
||||||
size_t j;
|
size_t j;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user