This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

an out-of-array bound access error in df-core.h


Hi, Seongbae,
  the following is the fix for the out-of-array access error, can you
help me to commit that to trunk, also i think it's applied to 4.3
branches.

Index: df-core.c
===================================================================
--- df-core.c   (revision 137589)
+++ df-core.c   (working copy)
@@ -622,7 +622,7 @@
        int j;
        for (j = i + 1; j < df->num_problems_defined; j++)
          df->problems_in_order[j-1] = df->problems_in_order[j];
-       df->problems_in_order[j] = NULL;
+       df->problems_in_order[j-1] = NULL;
        df->num_problems_defined--;
        break;
       }


bug detail:
when i =4, df->problems_in_order[4] == dflow, then it will try to move
the late problem backwards
such as:
df->problems_in_order[4] = df->problem_in_order[5]
now the j is 6, and df->num_problems_defined is 6

then after the for loop, it will assign NULL for the last index
df->problems_in_order[j] = NULL;

but we can see the array is declared as :
#define DF_SCAN  0
#define DF_LR    1      /* Live Registers backward. */
#define DF_LIVE  2      /* Live Registers & Uninitialized Registers */
#define DF_RD    3      /* Reaching Defs. */
#define DF_CHAIN 4      /* Def-Use and/or Use-Def Chains. */
#define DF_NOTE  5      /* REG_DEF and REG_UNUSED notes. */
#define DF_LAST_PROBLEM_PLUS1 (DF_NOTE + 1)

 struct dataflow *problems_in_order[DF_LAST_PROBLEM_PLUS1];

DF_LAST_PROBLEM_PLUS1 is 6, so we can't access problems_in_order[6],
it will be out of array bound,
here, store to df->problems_in_order[6] will override the value
problems_in_order[0], then df_scan will be NULL.

Previously we are lucky since we don't use up all these index, it's
exposed by my enhancement work in unrolling.



thanks.

Tianwei


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]