Skip to content

Commit ba9cf6b

Browse files
committed
media: pulse8-cec: fix data timestamp at pulse8_setup()
As pointed by Coverity, there is a hidden overflow condition there. As date is signed and u8 is unsigned, doing: date = (data[0] << 24) With a value bigger than 07f will make all upper bits of date 0xffffffff. This can be demonstrated with this small code: <code> typedef int64_t time64_t; typedef uint8_t u8; int main(void) { u8 data[] = { 0xde ,0xad , 0xbe, 0xef }; time64_t date; date = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; printf("Invalid data = 0x%08lx\n", date); date = ((unsigned)data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; printf("Expected data = 0x%08lx\n", date); return 0; } </code> Fix it by converting the upper bit calculation to unsigned. Fixes: cea28e7 ("media: pulse8-cec: reorganize function order") Cc: stable@vger.kernel.org Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent eba6a86 commit ba9cf6b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/media/cec/usb/pulse8/pulse8-cec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ static int pulse8_setup(struct pulse8 *pulse8, struct serio *serio,
685685
err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 4);
686686
if (err)
687687
return err;
688-
date = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
688+
date = ((unsigned)data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
689689
dev_info(pulse8->dev, "Firmware build date %ptT\n", &date);
690690

691691
dev_dbg(pulse8->dev, "Persistent config:\n");

0 commit comments

Comments
 (0)