]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[crypto] Avoid false positive warnings about out-of-bounds access master 1787/head
authorMichael Brown <mcb30@ipxe.org>
Mon, 3 Aug 2026 14:50:34 +0000 (15:50 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 3 Aug 2026 14:50:34 +0000 (15:50 +0100)
The last byte within a non-empty ASN.1 bit string object always
exists, but automated tools tend to erroneously report the way in
which we access it as being out of bounds.

Move the assignment of the last byte pointer to be ahead of the
shrinking of the cursor, to eliminate this class of false positive
warning.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/crypto/asn1.c

index 9a0e25649b20393703c3df698853319c258523bd..32745a098ba6b651d9c34901a00e9ee69841d246 100644 (file)
@@ -399,12 +399,12 @@ int asn1_enter_bits ( struct asn1_cursor *cursor, unsigned int *unused ) {
                return -EINVAL_BIT_STRING;
        }
        bit_string = cursor->data;
+       last = ( cursor->data + cursor->len - 1 );
        cursor->data = &bit_string->data;
        cursor->len -= offsetof ( typeof ( *bit_string ), data );
        unused_bits = bit_string->unused;
 
        /* Check validity of unused bits */
-       last = ( cursor->data + cursor->len - 1 );
        if ( ( unused_bits >= 8 ) ||
             ( ( unused_bits > 0 ) && ( cursor->len == 0 ) ) ||
             ( ( *last & ( 0xffU >> ( 8 - unused_bits ) ) ) != 0 ) ) {