mirror of
https://github.com/golang/go
synced 2024-11-13 18:00:30 -07:00
libmach: respect symbol table boundaries
Since fp->symsz includes the size of the header in the new symbol table format, we were reading past the end and decoding a few garbage symbols from data in the pc/line table. R=rsc, r CC=golang-dev https://golang.org/cl/7993043
This commit is contained in:
parent
8eaa942933
commit
d1eb9c8e0d
@ -109,7 +109,7 @@ int
|
||||
syminit(int fd, Fhdr *fp)
|
||||
{
|
||||
Sym *p;
|
||||
int32 i, l, size;
|
||||
int32 i, l, size, symsz;
|
||||
vlong vl;
|
||||
Biobuf b;
|
||||
int svalsz, newformat, shift;
|
||||
@ -138,6 +138,7 @@ syminit(int fd, Fhdr *fp)
|
||||
memset(buf, 0, sizeof buf);
|
||||
Bread(&b, buf, sizeof buf);
|
||||
newformat = 0;
|
||||
symsz = fp->symsz;
|
||||
if(memcmp(buf, "\xfd\xff\xff\xff\x00\x00\x00", 7) == 0) {
|
||||
swav = leswav;
|
||||
swal = leswal;
|
||||
@ -151,6 +152,7 @@ syminit(int fd, Fhdr *fp)
|
||||
swav = leswav;
|
||||
swal = leswal;
|
||||
Bseek(&b, fp->symoff+6, 0);
|
||||
symsz -= 6;
|
||||
} else {
|
||||
Bseek(&b, fp->symoff, 0);
|
||||
}
|
||||
@ -161,11 +163,12 @@ syminit(int fd, Fhdr *fp)
|
||||
werrstr("invalid word size %d bytes", svalsz);
|
||||
return -1;
|
||||
}
|
||||
symsz -= 8;
|
||||
}
|
||||
|
||||
nsym = 0;
|
||||
size = 0;
|
||||
for(p = symbols; size < fp->symsz; p++, nsym++) {
|
||||
for(p = symbols; size < symsz; p++, nsym++) {
|
||||
if(newformat) {
|
||||
// Go 1.1 format. See comment at top of ../pkg/runtime/symtab.c.
|
||||
if(Bread(&b, &c, 1) != 1)
|
||||
|
Loading…
Reference in New Issue
Block a user