mirror of
https://github.com/golang/go
synced 2024-11-26 13:38:20 -07:00
cmd/cc, cmd/ld: do not overflow strings in symbol lookup.
R=golang-dev, dave, minux.ma CC=golang-dev https://golang.org/cl/7876044
This commit is contained in:
parent
3add0fef1e
commit
77e7e4c329
@ -263,7 +263,7 @@ lookup(void)
|
|||||||
for(s = hash[h]; s != S; s = s->link) {
|
for(s = hash[h]; s != S; s = s->link) {
|
||||||
if(s->name[0] != c)
|
if(s->name[0] != c)
|
||||||
continue;
|
continue;
|
||||||
if(memcmp(s->name, symb, l) == 0)
|
if(strcmp(s->name, symb) == 0)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
s = alloc(sizeof(*s));
|
s = alloc(sizeof(*s));
|
||||||
|
@ -846,17 +846,16 @@ _lookup(char *symb, int v, int creat)
|
|||||||
Sym *s;
|
Sym *s;
|
||||||
char *p;
|
char *p;
|
||||||
int32 h;
|
int32 h;
|
||||||
int l, c;
|
int c;
|
||||||
|
|
||||||
h = v;
|
h = v;
|
||||||
for(p=symb; c = *p; p++)
|
for(p=symb; c = *p; p++)
|
||||||
h = h+h+h + c;
|
h = h+h+h + c;
|
||||||
l = (p - symb) + 1;
|
|
||||||
// not if(h < 0) h = ~h, because gcc 4.3 -O2 miscompiles it.
|
// not if(h < 0) h = ~h, because gcc 4.3 -O2 miscompiles it.
|
||||||
h &= 0xffffff;
|
h &= 0xffffff;
|
||||||
h %= NHASH;
|
h %= NHASH;
|
||||||
for(s = hash[h]; s != S; s = s->hash)
|
for(s = hash[h]; s != S; s = s->hash)
|
||||||
if(memcmp(s->name, symb, l) == 0)
|
if(strcmp(s->name, symb) == 0)
|
||||||
return s;
|
return s;
|
||||||
if(!creat)
|
if(!creat)
|
||||||
return nil;
|
return nil;
|
||||||
|
Loading…
Reference in New Issue
Block a user