Skip to contentSkip to conversation

target-i386: cpu: fix potential buffer overrun in get_register_name_32()

PATCH Applied Igor Mammedov 4 participants 4 messages Jun 3, 2013 – Jun 4, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-i386: cpu: fix potential buffer overrun in get_register_name_32()

spotted by Coverity,
x86_reg_info_32[] is CPU_NB_REGS32 elements long, so accessing x86_reg_info_32[CPU_NB_REGS32] will be one element off array.

---
 target-i386/cpu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-i386/cpu.c +1 -1
index 1a501d9..ae8e682 100644
@@ -221,7 +221,7 @@ X86RegisterInfo32 x86_reg_info_32[CPU_NB_REGS32] = {
 
 const char *get_register_name_32(unsigned int reg)
 {
-    if (reg > CPU_NB_REGS32) {
+    if (reg >= CPU_NB_REGS32) {
         return NULL;
     }
     return x86_reg_info_32[reg].name;
Signature · 1 line
1.7.1
#1 lore raw
Quoted 15 lines · Igor Mammedov

spotted by Coverity,
x86_reg_info_32[] is CPU_NB_REGS32 elements long, so accessing x86_reg_info_32[CPU_NB_REGS32] will be one element off array.

---
 target-i386/cpu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-i386/cpu.c +0 -0
index 1a501d9..ae8e682 100644

target-i386/cpu.c X86RegisterInfo32 x86_reg_info_32[CPU_NB_REGS32] = { · line 227

Quoted 8 lines
target-i386/cpu.c +1 -1
@@ -221,7 +221,7 @@ X86RegisterInfo32 x86_reg_info_32[CPU_NB_REGS32] = {
 
 const char *get_register_name_32(unsigned int reg)
 {
-    if (reg > CPU_NB_REGS32) {
+    if (reg >= CPU_NB_REGS32) {
         return NULL;
     }
     return x86_reg_info_32[reg].name;

Looks obvious now that it's been spotted. ;)

Reviewed by: Jesse Larrew <[email protected]>

Jesse Larrew
Software Engineer, KVM Team
IBM Linux Technology Center
Phone: (512) 973-2052 (T/L: 363-2052)
[email protected]

Reviewed-by on v1 1/1
#2 lore raw
In reply to Igor Mammedov
Quoted 3 lines · 在 2013-06-03一的 18:23 +0200,Igor Mammedov写道:

spotted by Coverity,
x86_reg_info_32[] is CPU_NB_REGS32 elements long, so accessing x86_reg_info_32[CPU_NB_REGS32] will be one element off array.

Yes, it will.

Quoted 19 lines
---
 target-i386/cpu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-i386/cpu.c +1 -1
index 1a501d9..ae8e682 100644
@@ -221,7 +221,7 @@ X86RegisterInfo32 x86_reg_info_32[CPU_NB_REGS32] = {
 
 const char *get_register_name_32(unsigned int reg)
 {
-    if (reg > CPU_NB_REGS32) {
+    if (reg >= CPU_NB_REGS32) {
         return NULL;
     }
     return x86_reg_info_32[reg].name;
#3 lore raw
In reply to Igor Mammedov

Am 03.06.2013 18:23, schrieb Igor Mammedov:

Quoted 8 lines

spotted by Coverity,
x86_reg_info_32[] is CPU_NB_REGS32 elements long, so accessing x86_reg_info_32[CPU_NB_REGS32] will be one element off array.

---
 target-i386/cpu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Thanks, applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg