]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
compression/huffman: check again for invalid codes (CID 1517302)
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Mon, 5 Dec 2022 22:24:22 +0000 (11:24 +1300)
committerJeremy Allison <jra@samba.org>
Mon, 19 Dec 2022 22:32:35 +0000 (22:32 +0000)
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>
lib/compression/lzxpress_huffman.c

index 7dd91f687fe79723fb8b60d5e0609549181035e1..c8e92383002976ff670b87d6122ad7875001eff1 100644 (file)
@@ -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);
 }