]> Cypherpunks repositories - gostls13.git/commitdiff
gc: reject large channel values at compile time
authorRuss Cox <rsc@golang.org>
Fri, 20 Nov 2009 02:20:06 +0000 (18:20 -0800)
committerRuss Cox <rsc@golang.org>
Fri, 20 Nov 2009 02:20:06 +0000 (18:20 -0800)
Fixes #144.

R=ken2
CC=agl1
https://golang.org/cl/156102

src/cmd/gc/align.c
src/cmd/gc/go.h

index d1cc9c23b61804ca743d9de2ac76d7e459b4e3c4..b74ac0f29f8778a2df021259c8c68a282800541b 100644 (file)
@@ -186,6 +186,18 @@ dowidth(Type *t)
        case TCHAN:             // implemented as pointer
                w = widthptr;
                checkwidth(t->type);
+
+               // make fake type to check later to
+               // trigger channel argument check.
+               t1 = typ(TCHANARGS);
+               t1->type = t;
+               checkwidth(t1);
+               break;
+       case TCHANARGS:
+               t1 = t->type;
+               dowidth(t->type);       // just in case
+               if(t1->type->width >= (1<<16))
+                       yyerror("channel element type too large (>64kB)");
                break;
        case TMAP:              // implemented as pointer
                w = widthptr;
index 7702efbf7437a96286f8deb3afeeb05b293e9f55..595d7c8b8c71d01b03ef27ff040d42e0c431e96b 100644 (file)
@@ -441,6 +441,7 @@ enum
        
        // pseudo-type for frame layout
        TFUNCARGS,
+       TCHANARGS,
 
        NTYPE,
 };