Commit 77e7e4c3 authored by Rémy Oudompheng's avatar Rémy Oudompheng

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
parent 3add0fef
......@@ -263,7 +263,7 @@ lookup(void)
for(s = hash[h]; s != S; s = s->link) {
if(s->name[0] != c)
continue;
if(memcmp(s->name, symb, l) == 0)
if(strcmp(s->name, symb) == 0)
return s;
}
s = alloc(sizeof(*s));
......
......@@ -846,17 +846,16 @@ _lookup(char *symb, int v, int creat)
Sym *s;
char *p;
int32 h;
int l, c;
int c;
h = v;
for(p=symb; c = *p; p++)
h = h+h+h + c;
l = (p - symb) + 1;
// not if(h < 0) h = ~h, because gcc 4.3 -O2 miscompiles it.
h &= 0xffffff;
h %= NHASH;
for(s = hash[h]; s != S; s = s->hash)
if(memcmp(s->name, symb, l) == 0)
if(strcmp(s->name, symb) == 0)
return s;
if(!creat)
return nil;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment