1
0
mirror of https://github.com/golang/go synced 2024-11-24 21:10:04 -07:00

avoid overflow of symb buffer in 5a/6a/8a/5c/6c/8c

R=rsc
CC=golang-dev
https://golang.org/cl/194099
This commit is contained in:
Dean Prichard 2010-01-28 16:11:38 -08:00 committed by Russ Cox
parent c9150003a9
commit 77053797e0
10 changed files with 56 additions and 8 deletions

View File

@ -142,6 +142,7 @@ EXTERN int32 lineno;
EXTERN int nerrors;
EXTERN int32 nhunk;
EXTERN int ninclude;
EXTERN int32 nsymb;
EXTERN Gen nullgen;
EXTERN char* outfile;
EXTERN int pass;
@ -149,7 +150,7 @@ EXTERN char* pathname;
EXTERN int32 pc;
EXTERN int peekc;
EXTERN int sym;
EXTERN char symb[NSYMB];
EXTERN char* symb;
EXTERN int thechar;
EXTERN char* thestring;
EXTERN int32 thunk;
@ -157,6 +158,7 @@ EXTERN Biobuf obuf;
void* alloc(int32);
void* allocn(void*, int32, int32);
void ensuresymb(int32);
void errorexit(void);
void pushio(void);
void newio(void);

View File

@ -57,6 +57,8 @@ main(int argc, char *argv[])
thechar = '5';
thestring = "arm";
ensuresymb(NSYMB);
memset(debug, 0, sizeof(debug));
cinit();
outfile = 0;

View File

@ -155,6 +155,7 @@ EXTERN int32 lineno;
EXTERN int nerrors;
EXTERN int32 nhunk;
EXTERN int ninclude;
EXTERN int32 nsymb;
EXTERN Gen nullgen;
EXTERN char* outfile;
EXTERN int pass;
@ -162,7 +163,7 @@ EXTERN char* pathname;
EXTERN int32 pc;
EXTERN int peekc;
EXTERN int sym;
EXTERN char symb[NSYMB];
EXTERN char* symb;
EXTERN int thechar;
EXTERN char* thestring;
EXTERN int32 thunk;
@ -170,6 +171,7 @@ EXTERN Biobuf obuf;
void* alloc(int32);
void* allocn(void*, int32, int32);
void ensuresymb(int32);
void errorexit(void);
void pushio(void);
void newio(void);

View File

@ -61,6 +61,7 @@ main(int argc, char *argv[])
thechar = '6';
thestring = "amd64";
ensuresymb(NSYMB);
memset(debug, 0, sizeof(debug));
cinit();
outfile = 0;

View File

@ -156,6 +156,7 @@ EXTERN int32 lineno;
EXTERN int nerrors;
EXTERN int32 nhunk;
EXTERN int ninclude;
EXTERN int32 nsymb;
EXTERN Gen nullgen;
EXTERN char* outfile;
EXTERN int pass;
@ -163,7 +164,7 @@ EXTERN char* pathname;
EXTERN int32 pc;
EXTERN int peekc;
EXTERN int sym;
EXTERN char symb[NSYMB];
EXTERN char* symb;
EXTERN int thechar;
EXTERN char* thestring;
EXTERN int32 thunk;
@ -171,6 +172,7 @@ EXTERN Biobuf obuf;
void* alloc(int32);
void* allocn(void*, int32, int32);
void ensuresymb(int32);
void errorexit(void);
void pushio(void);
void newio(void);

View File

@ -60,6 +60,8 @@ main(int argc, char *argv[])
thechar = '8';
thestring = "386";
ensuresymb(NSYMB);
memset(debug, 0, sizeof(debug));
cinit();
outfile = 0;

View File

@ -492,6 +492,7 @@ EXTERN int32 nhunk;
EXTERN int ninclude;
EXTERN Node* nodproto;
EXTERN Node* nodcast;
EXTERN int32 nsymb;
EXTERN Biobuf outbuf;
EXTERN Biobuf diagbuf;
EXTERN char* outfile;
@ -500,7 +501,7 @@ EXTERN int peekc;
EXTERN int32 stkoff;
EXTERN Type* strf;
EXTERN Type* strl;
EXTERN char symb[NSYMB];
EXTERN char* symb;
EXTERN Sym* symstring;
EXTERN int taggen;
EXTERN Type* tfield;
@ -573,6 +574,7 @@ int mpatov(char*, vlong*);
*/
void* allocn(void*, int32, int32);
void* alloc(int32);
void ensuresymb(int32);
void cinit(void);
int compile(char*, char**, int);
void errorexit(void);

View File

@ -85,6 +85,7 @@ main(int argc, char *argv[])
char *defs[50], *p;
int nproc, nout, i, c, ndef;
ensuresymb(NSYMB);
memset(debug, 0, sizeof(debug));
tinit();
cinit();
@ -392,7 +393,7 @@ newfile(char *s, int f)
Sym*
slookup(char *s)
{
ensuresymb(strlen(s));
strcpy(symb, s);
return lookup();
}
@ -408,7 +409,9 @@ lookup(void)
if((uchar)symb[0] == 0xc2 && (uchar)symb[1] == 0xb7) {
// turn leading · into ""·
memmove(symb+2, symb, strlen(symb)+1);
h = strlen(symb);
ensuresymb(h+2);
memmove(symb+2, symb, h+1);
symb[0] = '"';
symb[1] = '"';
}
@ -1584,3 +1587,17 @@ allocn(void *p, int32 n, int32 d)
memset((char*)p+n, 0, d);
return p;
}
void
ensuresymb(int32 n)
{
if(symb == nil) {
symb = alloc(NSYMB+1);
nsymb = NSYMB;
}
if(n > nsymb) {
symb = allocn(symb, nsymb, n+1-nsymb);
nsymb = n;
}
}

View File

@ -125,6 +125,20 @@ allocn(void *p, int32 on, int32 n)
return p;
}
void
ensuresymb(int32 n)
{
if(symb == nil) {
symb = alloc(NSYMB+1);
nsymb = NSYMB;
}
if(n > nsymb) {
symb = allocn(symb, nsymb, n+1-nsymb);
nsymb = n;
}
}
void
setinclude(char *p)
{
@ -209,7 +223,7 @@ newfile(char *s, int f)
Sym*
slookup(char *s)
{
ensuresymb(strlen(s));
strcpy(symb, s);
return lookup();
}
@ -225,7 +239,9 @@ lookup(void)
if((uchar)symb[0] == 0xc2 && (uchar)symb[1] == 0xb7) {
// turn leading · into ""·
memmove(symb+2, symb, strlen(symb)+1);
h = strlen(symb);
ensuresymb(h+2);
memmove(symb+2, symb, h+1);
symb[0] = '"';
symb[1] = '"';
}

View File

@ -140,6 +140,7 @@ dodefine(char *cp)
char *p;
int32 l;
ensuresymb(strlen(cp));
strcpy(symb, cp);
p = strchr(symb, '=');
if(p) {
@ -574,6 +575,7 @@ macinc(void)
for(i=0; i<ninclude; i++) {
if(i == 0 && c0 == '>')
continue;
ensuresymb(strlen(include[i])+strlen(str)+2);
strcpy(symb, include[i]);
strcat(symb, "/");
if(strcmp(symb, "./") == 0)