[hackers] [scc] Check correctness of indexes in designators || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 20 Jan 2016 16:02:24 +0100 (CET)

commit 7c8e979f1d5f58982cae51893eec769c28b716b3
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Jan 20 15:53:41 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Jan 20 15:53:41 2016 +0100

    Check correctness of indexes in designators
    
    This is an error and can generate a segmentation fault if
    it is not controlled.

diff --git a/cc1/init.c b/cc1/init.c
index f2b7509..796cb0a 100644
--- a/cc1/init.c
+++ b/cc1/init.c
_AT_@ -31,12 +31,17 @@ arydesig(Init *ip)
 {
         TINT npos;
         Node *np;
+ Type *tp = ip->type;
 
         if (ip->type->op != ARY)
                 errorp("array index in non-array initializer");
         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;
Received on Wed Jan 20 2016 - 16:02:24 CET

This archive was generated by hypermail 2.3.0 : Wed Jan 20 2016 - 16:12:29 CET