read_ilang: do bounds checking on bit indices
authorMarcin Kościelnicki <koriakin@0x04.net>
Wed, 27 Nov 2019 21:24:39 +0000 (22:24 +0100)
committerMarcin Kościelnicki <koriakin@0x04.net>
Wed, 27 Nov 2019 21:24:39 +0000 (22:24 +0100)
frontends/ilang/ilang_parser.y

index b4b9693dafb030db3c1839139332de2b049360bc..4e0b62edd9426b2057e595d34e2e716a7c76a46c 100644 (file)
@@ -430,10 +430,14 @@ sigspec:
                free($1);
        } |
        sigspec '[' TOK_INT ']' {
+               if ($3 >= $1->size() || $3 < 0)
+                       rtlil_frontend_ilang_yyerror("bit index out of range");
                $$ = new RTLIL::SigSpec($1->extract($3));
                delete $1;
        } |
        sigspec '[' TOK_INT ':' TOK_INT ']' {
+               if ($3 >= $1->size() || $3 < 0 || $3 < $5)
+                       rtlil_frontend_ilang_yyerror("invalid slice");
                $$ = new RTLIL::SigSpec($1->extract($5, $3 - $5 + 1));
                delete $1;
        } |