scsi: Silence gcc warning
PATCH 1/1 scsi: Silence gcc warning
On Fedora 33, gcc 10.2.1 notes that scsi_cdb_length(buf) can set len==-1, which in turn overflows g_malloc():
[5/5] Linking target qemu-system-x86_64
In function ‘scsi_disk_new_request_dump’,
inlined from ‘scsi_new_request’ at ../hw/scsi/scsi-disk.c:2608:9:../hw/scsi/scsi-disk.c:2582:19: warning: argument 1 value ‘18446744073709551612’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
2582 | line_buffer = g_malloc(len * 5 + 1);
| ^
Silence it with a decent assertion, since we only convert a buffer to bytes when we have a valid cdb length.
--- hw/scsi/scsi-disk.c | 1 + 1 file changed, 1 insertion(+)
hw/scsi/scsi-disk.c +1 -0
@@ -2579,6 +2579,7 @@ static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf)int len =scsi_cdb_length (buf);char *line_buffer, *p; +assert (len >0 && len <=16 ); line_buffer =g_malloc (len *5 +1 );for (i =0 , p = line_buffer; i < len; i++) {
Signature · 1 line
2.30.0
Quoted 24 lines · Eric Blake
On Fedora 33, gcc 10.2.1 notes that
scsi_cdb_length(buf)can set len==-1, which in turn overflowsg_malloc():[5/5] Linking target qemu-system-x86_64
In function ‘scsi_disk_new_request_dump’,
inlined from ‘scsi_new_request’ at../hw/scsi/scsi-disk.c:2608:9:../hw/scsi/scsi-disk.c:2582:19: warning: argument 1 value ‘18446744073709551612’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
2582 |line_buffer=g_malloc(len * 5 + 1);
| ^Silence it with a decent assertion, since we only convert a buffer to bytes when we have a valid cdb length.
Signed-off-by Eric Blake <[email protected]>--- hw/scsi/scsi-disk.c | 1 + 1 file changed, 1 insertion(+)hw/scsi/scsi-disk.c +0
-0
hw/scsi/scsi-disk.c static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf) · line 2585
Quoted 7 lines
hw/scsi/scsi-disk.c +1
-0@@ -2579,6 +2579,7 @@ static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf)int len =scsi_cdb_length (buf);char *line_buffer, *p; +assert (len >0 && len <=16 ); line_buffer =g_malloc (len *5 +1 );for (i =0 , p = line_buffer; i < len; i++) {
Adding qemu-trivial in cc.
Quoted 35 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Eric Blake
On Fedora 33, gcc 10.2.1 notes that
scsi_cdb_length(buf)can set len==-1, which in turn overflowsg_malloc():[5/5] Linking target qemu-system-x86_64
In function ‘scsi_disk_new_request_dump’,
inlined from ‘scsi_new_request’ at../hw/scsi/scsi-disk.c:2608:9:../hw/scsi/scsi-disk.c:2582:19: warning: argument 1 value ‘18446744073709551612’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
2582 |line_buffer=g_malloc(len * 5 + 1);
| ^Silence it with a decent assertion, since we only convert a buffer to bytes when we have a valid cdb length.
Signed-off-by Eric Blake <[email protected]>--- hw/scsi/scsi-disk.c | 1 + 1 file changed, 1 insertion(+)hw/scsi/scsi-disk.c +0
-0hw/scsi/scsi-disk.c static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf) · line 2585
Quoted 7 lines
hw/scsi/scsi-disk.c +1
-0@@ -2579,6 +2579,7 @@ static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf)int len =scsi_cdb_length (buf);char *line_buffer, *p; +assert (len >0 && len <=16 ); line_buffer =g_malloc (len *5 +1 );for (i =0 , p = line_buffer; i < len; i++) {Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Laurent Vivier
AppliedLe 08/03/2021 à 20:54, Eric Blake a écrit :
Quoted 39 lines
Adding qemu-trivial in cc.
Quoted 35 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Eric Blake
On Fedora 33, gcc 10.2.1 notes that
scsi_cdb_length(buf)can set len==-1, which in turn overflowsg_malloc():[5/5] Linking target qemu-system-x86_64
In function ‘scsi_disk_new_request_dump’,
inlined from ‘scsi_new_request’ at../hw/scsi/scsi-disk.c:2608:9:../hw/scsi/scsi-disk.c:2582:19: warning: argument 1 value ‘18446744073709551612’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
2582 |line_buffer=g_malloc(len * 5 + 1);
| ^Silence it with a decent assertion, since we only convert a buffer to bytes when we have a valid cdb length.
Signed-off-by Eric Blake <[email protected]>--- hw/scsi/scsi-disk.c | 1 + 1 file changed, 1 insertion(+)hw/scsi/scsi-disk.c +0
-0hw/scsi/scsi-disk.c static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf) · line 2585
Quoted 7 lines
hw/scsi/scsi-disk.c +1
-0@@ -2579,6 +2579,7 @@ static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf)int len =scsi_cdb_length (buf);char *line_buffer, *p; +assert (len >0 && len <=16 ); line_buffer =g_malloc (len *5 +1 );for (i =0 , p = line_buffer; i < len; i++) {Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Applied to my trivial-patches branch.
Thanks,
Laurent