util/cutils: Fix Coverity array overrun in freq_to_str()
PATCH v3 1/1 util/cutils: Fix Coverity array overrun in freq_to_str()
Fix Coverity CID 1435957: Memory - illegal accesses (OVERRUN):
Quoted 1 line
Quoted 1 line
Quoted 1 line
Overrunning array "suffixes" of 7 8-byte elements at element
index 7 (byte offset 63) using index "idx" (which evaluates to 7).
Note, the biggest input value freq_to_str() can accept is UINT64_MAX, which is ~18.446 EHz, less than 1000 EHz.
---
v3: Follow Peter's suggestion
--- util/cutils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
util/cutils.c +2 -1
@@ -891,10 +891,11 @@ char *freq_to_str(uint64_t freq_hz)double freq = freq_hz;size_t idx =0 ; -while (freq >=1000.0 && idx <ARRAY_SIZE (suffixes)) { +while (freq >=1000.0 ) { freq /=1000.0 ; idx++; } +assert (idx <ARRAY_SIZE (suffixes));return g_strdup_printf ("%0.3g %sHz" , freq, suffixes[idx]); }
Signature · 1 line
2.26.2
Quoted 26 lines · Philippe Mathieu-Daudé
Fix Coverity CID 1435957: Memory - illegal accesses (OVERRUN):
Quoted 1 line
Quoted 1 line
Quoted 1 line
Overrunning array "suffixes" of 7 8-byte elements at element
index 7 (byte offset 63) using index "idx" (which evaluates to 7).
Note, the biggest input value
freq_to_str()can accept isUINT64_MAX, which is ~18.446 EHz, less than 1000 EHz.Reported-by Eduardo Habkost <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
v3: Follow Peter's suggestion--- util/cutils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)util/cutils.c +0
-0@@ -891,10 +891,11 @@ char *freq_to_str(uint64_t freq_hz)double freq = freq_hz;size_t idx =0 ;
util/cutils.c char *freq_to_str(uint64_t freq_hz)
Quoted 10 lines
util/cutils.c +2
-2-while (freq >=1000.0 && idx <ARRAY_SIZE (suffixes)) { +while (freq >=1000.0 ) { freq /=1000.0 ; idx++; } +assert (idx <ARRAY_SIZE (suffixes));return g_strdup_printf ("%0.3g %sHz" , freq, suffixes[idx]); } --
thanks
-- PMM
Quoted 11 lines · Philippe Mathieu-Daudé
Fix Coverity CID 1435957: Memory - illegal accesses (OVERRUN):
Quoted 1 line
Quoted 1 line
Quoted 1 line
Overrunning array "suffixes" of 7 8-byte elements at element
index 7 (byte offset 63) using index "idx" (which evaluates to 7).
Note, the biggest input value
freq_to_str()can accept isUINT64_MAX, which is ~18.446 EHz, less than 1000 EHz.Reported-by Eduardo Habkost <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks for taking the time to fix this!
Signature · 1 line
Eduardo
Quoted 11 lines · Philippe Mathieu-Daudé
Fix Coverity CID 1435957: Memory - illegal accesses (OVERRUN):
Quoted 1 line
Quoted 1 line
Quoted 1 line
Overrunning array "suffixes" of 7 8-byte elements at element
index 7 (byte offset 63) using index "idx" (which evaluates to 7).
Note, the biggest input value
freq_to_str()can accept isUINT64_MAX, which is ~18.446 EHz, less than 1000 EHz.Reported-by Eduardo Habkost <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 26 lines
---
v3: Follow Peter's suggestion--- util/cutils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)util/cutils.c +2
-1@@ -891,10 +891,11 @@ char *freq_to_str(uint64_t freq_hz)double freq = freq_hz;size_t idx =0 ; -while (freq >=1000.0 && idx <ARRAY_SIZE (suffixes)) { +while (freq >=1000.0 ) { freq /=1000.0 ; idx++; } +assert (idx <ARRAY_SIZE (suffixes));return g_strdup_printf ("%0.3g %sHz" , freq, suffixes[idx]); }Signature · 1 line
2.26.2
Quoted 6 lines · Philippe Mathieu-Daudé
Fix Coverity CID 1435957: Memory - illegal accesses (OVERRUN):
Quoted 1 line
Quoted 1 line
Quoted 1 line
Overrunning array "suffixes" of 7 8-byte elements at element
index 7 (byte offset 63) using index "idx" (which evaluates to 7).
Quoted 8 lines
Note, the biggest input value
freq_to_str()can accept isUINT64_MAX, which is ~18.446 EHz, less than 1000 EHz.Reported-by Eduardo Habkost <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
v3: Follow Peter's suggestion
Since nobody else has picked this up I'll take it via target-arm.next.
thanks
-- PMM