Commit d1eb9c8e authored by Anthony Martin's avatar Anthony Martin

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
parent 8eaa9429
...@@ -109,7 +109,7 @@ int ...@@ -109,7 +109,7 @@ int
syminit(int fd, Fhdr *fp) syminit(int fd, Fhdr *fp)
{ {
Sym *p; Sym *p;
int32 i, l, size; int32 i, l, size, symsz;
vlong vl; vlong vl;
Biobuf b; Biobuf b;
int svalsz, newformat, shift; int svalsz, newformat, shift;
...@@ -138,6 +138,7 @@ syminit(int fd, Fhdr *fp) ...@@ -138,6 +138,7 @@ syminit(int fd, Fhdr *fp)
memset(buf, 0, sizeof buf); memset(buf, 0, sizeof buf);
Bread(&b, buf, sizeof buf); Bread(&b, buf, sizeof buf);
newformat = 0; newformat = 0;
symsz = fp->symsz;
if(memcmp(buf, "\xfd\xff\xff\xff\x00\x00\x00", 7) == 0) { if(memcmp(buf, "\xfd\xff\xff\xff\x00\x00\x00", 7) == 0) {
swav = leswav; swav = leswav;
swal = leswal; swal = leswal;
...@@ -151,6 +152,7 @@ syminit(int fd, Fhdr *fp) ...@@ -151,6 +152,7 @@ syminit(int fd, Fhdr *fp)
swav = leswav; swav = leswav;
swal = leswal; swal = leswal;
Bseek(&b, fp->symoff+6, 0); Bseek(&b, fp->symoff+6, 0);
symsz -= 6;
} else { } else {
Bseek(&b, fp->symoff, 0); Bseek(&b, fp->symoff, 0);
} }
...@@ -161,11 +163,12 @@ syminit(int fd, Fhdr *fp) ...@@ -161,11 +163,12 @@ syminit(int fd, Fhdr *fp)
werrstr("invalid word size %d bytes", svalsz); werrstr("invalid word size %d bytes", svalsz);
return -1; return -1;
} }
symsz -= 8;
} }
nsym = 0; nsym = 0;
size = 0; size = 0;
for(p = symbols; size < fp->symsz; p++, nsym++) { for(p = symbols; size < symsz; p++, nsym++) {
if(newformat) { if(newformat) {
// Go 1.1 format. See comment at top of ../pkg/runtime/symtab.c. // Go 1.1 format. See comment at top of ../pkg/runtime/symtab.c.
if(Bread(&b, &c, 1) != 1) if(Bread(&b, &c, 1) != 1)
......
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