ref: 7c8e979f1d5f58982cae51893eec769c28b716b3
parent: b79fb78e5800e18978ed22288e8ad3bf6702cf0d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Jan 20 10:53:41 EST 2016
Check correctness of indexes in designators This is an error and can generate a segmentation fault if it is not controlled.
--- a/cc1/init.c
+++ b/cc1/init.c
@@ -31,6 +31,7 @@
{
TINT npos;
Node *np;
+ Type *tp = ip->type;
if (ip->type->op != ARY)
errorp("array index in non-array initializer");
@@ -37,6 +38,10 @@
next();
np = iconstexpr();
npos = np->sym->u.i;
+ if (npos < 0 || tp->defined && npos >= tp->n.elem) {
+ errorp("array index in initializer exceeds array bounds");
+ npos = 0;
+ }
freetree(np);
expect(']');
return npos;