]> git.ipfire.org Git - thirdparty/krb5.git/commit
Prevent undefined shift in decode_krb5_flags() 1389/head
authorGreg Hudson <ghudson@mit.edu>
Wed, 6 Nov 2024 22:31:37 +0000 (17:31 -0500)
committerGreg Hudson <ghudson@mit.edu>
Mon, 11 Nov 2024 21:24:06 +0000 (16:24 -0500)
commitd09433aed821d40142b10dc5b4a0aa8110c5a09e
tree828c7cfe7665c4190f7698a775b02b61308c87e4
parentead2a8b253c7db8d17a0765044947c5fbd564bc4
Prevent undefined shift in decode_krb5_flags()

In the statement "f |= bits[i] << (8 * (3 - i))", bits[i] is
implicitly promoted from uint8_t to int according to the integer
promotion rules (C99 6.3.1.1).  If i is 0 and bits[i] >= 128, the
result cannot be represented as an int and the behavior of the shift
is undefined (C99 6.5.7).  To ensure that the shift operation is
defined, cast bits[i] to uint32_t.

(f and the function output are int32_t, but the conversion of uint32_t
to int32_t is implementation-defined when the value cannot be
represented, not undefined.  We check in configure.ac that the
platform is two's complement.)

(Discovered by OSS-Fuzz.)
src/lib/krb5/asn.1/asn1_k_encode.c