diff options
author | Douglas Bagnall <douglas.bagnall@catalyst.net.nz> | 2022-12-06 11:24:22 +1300 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2022-12-19 22:32:35 +0000 |
commit | d6a67908e13dd46b3bd336adae97e26920bb7f90 (patch) | |
tree | 7a0941ef7bf9a5452bcd5e827250259367116870 /lib/compression | |
parent | 27af27f9018b8bf32eac8ae79401354f6f18a4c6 (diff) | |
download | samba-d6a67908e13dd46b3bd336adae97e26920bb7f90.tar.gz |
compression/huffman: check again for invalid codes (CID 1517302)
We know that code is non-zero, because it comes from the combination of
the intermediate representation and the symbol tables that were generated
at the same time. But Coverity doesn't know that, and it thinks we could
be doing undefined things in the subsequent shift.
CID 1517302: Integer handling issues (BAD_SHIFT)
In expression "1 << code_bit_len", shifting by a negative amount has
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/compression')
-rw-r--r-- | lib/compression/lzxpress_huffman.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/compression/lzxpress_huffman.c b/lib/compression/lzxpress_huffman.c index 7dd91f687fe..c8e92383002 100644 --- a/lib/compression/lzxpress_huffman.c +++ b/lib/compression/lzxpress_huffman.c @@ -970,6 +970,9 @@ static inline bool write_bits(struct write_context *wc, static inline bool write_code(struct write_context *wc, uint16_t code) { int code_bit_len = bitlen_nonzero_16(code); + if (unlikely(code == 0)) { + return false; + } code &= (1 << code_bit_len) - 1; return write_bits(wc, code, code_bit_len); } |