Skip to contentSkip to conversation

hw/fmopl: Fix buffer access out-of-bounds errors

PATCH Superseded Stefan Weil 2 participants 3 messages Jan 15, 2011 – Mar 13, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/fmopl: Fix buffer access out-of-bounds errors

Index 75 is one too large for AR_TABLE[75], DR_TABLE[75]. This error was reported by cppcheck.

hw/fmopl.c:600: error: Buffer access out-of-bounds: OPL.AR_TABLE hw/fmopl.c:601: error: Buffer access out-of-bounds: OPL.DR_TABLE

Fix this by limiting the access to the allowed range. MultiArcadeMachineEmulator has newer versions of fmopl, but using these requires more efforts.

---
 hw/fmopl.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
hw/fmopl.c +5 -1
index 3df1806..d8a0f36 100644
@@ -45,6 +45,10 @@
 #define PI 3.14159265358979323846
 #endif
 
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
+
 /* -------------------- for debug --------------------- */
 /* #define OPL_OUTPUT_LOG */
 #ifdef OPL_OUTPUT_LOG
@@ -595,7 +599,7 @@ static void init_timetables( FM_OPL *OPL , int ARRATE , int DRRATE )
 		OPL->AR_TABLE[i] = rate / ARRATE;
 		OPL->DR_TABLE[i] = rate / DRRATE;
 	}
-	for (i = 60;i < 76;i++)
+	for (i = 60; i < ARRAY_SIZE(OPL->AR_TABLE); i++)
 	{
 		OPL->AR_TABLE[i] = EG_AED-1;
 		OPL->DR_TABLE[i] = OPL->DR_TABLE[60];
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH RESEND 1/1 hw/fmopl: Fix buffer access out-of-bounds errors

Index 75 is one too large for AR_TABLE[75], DR_TABLE[75]. This error was reported by cppcheck.

hw/fmopl.c:600: error: Buffer access out-of-bounds: OPL.AR_TABLE hw/fmopl.c:601: error: Buffer access out-of-bounds: OPL.DR_TABLE

Fix this by limiting the access to the allowed range. MultiArcadeMachineEmulator has newer versions of fmopl, but using these requires more efforts.

---
 hw/fmopl.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
hw/fmopl.c +5 -1
index 3df1806..d8a0f36 100644
@@ -45,6 +45,10 @@
 #define PI 3.14159265358979323846
 #endif
 
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
+
 /* -------------------- for debug --------------------- */
 /* #define OPL_OUTPUT_LOG */
 #ifdef OPL_OUTPUT_LOG
@@ -595,7 +599,7 @@ static void init_timetables( FM_OPL *OPL , int ARRATE , int DRRATE )
 		OPL->AR_TABLE[i] = rate / ARRATE;
 		OPL->DR_TABLE[i] = rate / DRRATE;
 	}
-	for (i = 60;i < 76;i++)
+	for (i = 60; i < ARRAY_SIZE(OPL->AR_TABLE); i++)
 	{
 		OPL->AR_TABLE[i] = EG_AED-1;
 		OPL->DR_TABLE[i] = OPL->DR_TABLE[60];
Signature · 1 line
1.7.2.3
Applied
#2 lore raw

Thanks, applied.

Quoted 45 lines · Stefan Weil

Index 75 is one too large for AR_TABLE[75], DR_TABLE[75]. This error was reported by cppcheck.

hw/fmopl.c:600: error: Buffer access out-of-bounds: OPL.AR_TABLE hw/fmopl.c:601: error: Buffer access out-of-bounds: OPL.DR_TABLE

Fix this by limiting the access to the allowed range. MultiArcadeMachineEmulator has newer versions of fmopl, but using these requires more efforts.

---
 hw/fmopl.c |    6 +++++-

 1 files changed, 5 insertions(+), 1 deletions(-)
hw/fmopl.c +5 -2
index 3df1806..d8a0f36 100644
@@ -45,6 +45,10 @@
  #define PI 3.14159265358979323846
  #endif
 
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
+
  /* -------------------- for debug --------------------- */
  /* #define OPL_OUTPUT_LOG */
  #ifdef OPL_OUTPUT_LOG
@@ -595,7 +599,7 @@ static void init_timetables( FM_OPL *OPL , int ARRATE , int DRRATE )
                OPL->AR_TABLE[i] = rate / ARRATE;
                OPL->DR_TABLE[i] = rate / DRRATE;
        }
-       for (i = 60;i < 76;i++)
+       for (i = 60; i < ARRAY_SIZE(OPL->AR_TABLE); i++)
        {
                OPL->AR_TABLE[i] = EG_AED-1;
                OPL->DR_TABLE[i] = OPL->DR_TABLE[60];
--

1.7.2.3