Browse code

Fix use-of-uninit memory on zeroinitializer.

Török Edvin authored on 2010/03/30 16:42:46
Showing 1 changed files
... ...
@@ -811,6 +811,13 @@ static void readConstant(struct cli_bc *bc, unsigned i, unsigned comp,
811 811
 			 unsigned len, char *ok)
812 812
 {
813 813
     unsigned j=0;
814
+    if (*ok && buffer[*offset] == 0x40 &&
815
+	buffer [*offset+1] == 0x60) {
816
+	/* zero initializer */
817
+	memset(bc->globals[i], 0, sizeof(*bc->globals[0])*comp);
818
+	(*offset)+=2;
819
+	return;
820
+    }
814 821
     while (*ok && buffer[*offset] != 0x60) {
815 822
 	if (j >= comp) {
816 823
 	    cli_errmsg("bytecode: constant has too many subcomponents, expected %u\n", comp);
... ...
@@ -821,8 +828,8 @@ static void readConstant(struct cli_bc *bc, unsigned i, unsigned comp,
821 821
 	bc->globals[i][j++] = readNumber(buffer, offset, len, ok);
822 822
     }
823 823
     if (*ok && j != comp) {
824
-	cli_dbgmsg("bytecode: constant has too few subcomponents: %u < %u\n", j, comp);
825
-/*	*ok = 0; */
824
+	cli_errmsg("bytecode: constant has too few subcomponents: %u < %u\n", j, comp);
825
+	*ok = 0;
826 826
     }
827 827
     (*offset)++;
828 828
 }