[svn:parrot] r45939 - trunk/compilers/imcc

darbelo at svn.parrot.org darbelo at svn.parrot.org
Fri Apr 23 18:05:54 UTC 2010


Author: darbelo
Date: Fri Apr 23 18:05:53 2010
New Revision: 45939
URL: https://trac.parrot.org/parrot/changeset/45939

Log:
Rename KEYLEN to MAX_KEY_LEN and use to indicate actual key length instead of available buffer space and make key[] big enough to *always* hold MAX_KEY_LEN items.
This fixes the stack corruption issues in OpenBSD/amd64.

Modified:
   trunk/compilers/imcc/pbc.c

Modified: trunk/compilers/imcc/pbc.c
==============================================================================
--- trunk/compilers/imcc/pbc.c	Fri Apr 23 09:18:10 2010	(r45938)
+++ trunk/compilers/imcc/pbc.c	Fri Apr 23 18:05:53 2010	(r45939)
@@ -1538,13 +1538,14 @@
 build_key(PARROT_INTERP, ARGIN(SymReg *key_reg))
 {
     ASSERT_ARGS(build_key)
-#define KEYLEN 21
-    SymReg   *reg;
+#define MAX_KEY_LEN 10
+#define MAX_KEYNAME_LEN 20
+    SymReg   *reg = key_reg->set == 'K' ? key_reg->nextkey : key_reg;
 
-    char      s_key[KEYLEN * 10];
-    opcode_t  key[KEYLEN + 1]; /* [0] -> length, [1..] -> keys */
+    char      s_key[MAX_KEY_LEN * MAX_KEYNAME_LEN];
+    opcode_t  key[MAX_KEY_LEN * 2 + 1];
     opcode_t  size;
-    int       key_length;     /* P0["hi;there"; S0; 2] has length 3 */
+    int       key_length = 0;     /* P0["hi;there"; S0; 2] has length 3 */
     int       k;
 
     /* 0 is length */
@@ -1554,15 +1555,14 @@
     char     *s  = s_key;
 
     *s           = 0;
-    reg          = key_reg->set == 'K' ? key_reg->nextkey : key_reg;
 
     for (key_length = 0; reg ; reg = reg->nextkey, key_length++) {
         SymReg *r = reg;
         int     type;
 
-        if ((pc - key - 2) >= KEYLEN)
+        if (key_length >= MAX_KEY_LEN)
             IMCC_fatal(interp, 1, "build_key:"
-                    "key too complex increase KEYLEN\n");
+                    "Key too long, increase MAX_KEY_LEN.\n");
 
         /* if key is a register, the original sym is in r->reg */
         type = r->type;


More information about the parrot-commits mailing list