Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: gpib: avoid unintended sign extension

The code was basically like this (assuming size_t can be u64)
var_u64 |= var_u8 << 24
var_u8 is first promoted to i32 and then the shift is done. Next, it is
promoted to u64 by first signextending to 64 bits. This is very unlikely
what was intended. So now it is first forced to u32.
var_u64 |= (u32)var_u8 << 24

This was detected by Coverity, CID 1600792.

Fixes: 4c41fe886a56 ("staging: gpib: Add Agilent/Keysight 82357x USB GPIB driver")
Signed-off-by: Kees Bakker <kees@ijzerbout.nl>
Link: https://lore.kernel.org/r/20241108201207.1194F18DDF5@bout3.ijzerbout.nl
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Kees Bakker and committed by
Greg Kroah-Hartman
e27cd679 73453164

+4 -4
+4 -4
drivers/staging/gpib/agilent_82357a/agilent_82357a.c
··· 664 664 kfree(status_data); 665 665 return -EIO; 666 666 } 667 - *bytes_written = status_data[2]; 668 - *bytes_written |= status_data[3] << 8; 669 - *bytes_written |= status_data[4] << 16; 670 - *bytes_written |= status_data[5] << 24; 667 + *bytes_written = (u32)status_data[2]; 668 + *bytes_written |= (u32)status_data[3] << 8; 669 + *bytes_written |= (u32)status_data[4] << 16; 670 + *bytes_written |= (u32)status_data[5] << 24; 671 671 672 672 kfree(status_data); 673 673 return 0;