prevent unintended sign extension errors

When an unsigned char is shifted << 24 bits its type will be
promoted to signed 32-bits.   If the value is then assigned to
an unsigned 64-bit value sign extension will occur.

Prevent the unwanted sign extension by explicitly casting the
value to unsigned long before shifting.

Change-Id: Iabeac0f17dc3229a2dc89abe71960a8ffbf523f8
This commit is contained in:
Jeffrey Altman
2022-01-16 00:06:01 -05:00
committed by Jeffrey Altman
parent 3707c52ea7
commit f341fa7721
6 changed files with 10 additions and 7 deletions

View File

@@ -1253,7 +1253,8 @@ fill_input(krb5_context context, slave *s)
return EWOULDBLOCK;
buf = s->input.header_buf;
len = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
len = ((unsigned long)buf[0] << 24) | (buf[1] << 16)
| (buf[2] << 8) | buf[3];
if (len > SLAVE_MSG_MAX)
return EINVAL;
ret = krb5_data_alloc(&s->input.packet, len);