This patch prevents integer underflow when the length was too small,
which could lead to memory corruption.
Signed-off-by: Jeremy Boone <jeremy.boone@nccgroup.trust>
static int st33zp24_i2c_recv(struct udevice *dev, u8 *buf, size_t count)
{
struct tpm_chip *chip = dev_get_priv(dev);
- int size, expected;
+ int size;
+ unsigned int expected;
if (!chip)
return -ENODEV;
}
expected = get_unaligned_be32(buf + 2);
- if (expected > count) {
+ if (expected > count || expected < TPM_HEADER_SIZE) {
size = -EIO;
goto out;
}
static int st33zp24_spi_recv(struct udevice *dev, u8 *buf, size_t count)
{
struct tpm_chip *chip = dev_get_priv(dev);
- int size, expected;
+ int size;
+ unsigned int expected;
if (!chip)
return -ENODEV;
}
expected = get_unaligned_be32(buf + 2);
- if (expected > count) {
+ if (expected > count || expected < TPM_HEADER_SIZE) {
size = -EIO;
goto out;
}