cmd/link: check magic header

Change-Id: I84b0e1d86728a76bc6a87fee4accf6fc43d87006
Reviewed-on: https://go-review.googlesource.com/54814
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Hiroshi Ioka 2017-07-25 11:34:30 +09:00 committed by Ian Lance Taylor
parent 392834ff2b
commit d02647242d
2 changed files with 14 additions and 1 deletions

View file

@ -724,8 +724,17 @@ func genhash(ctxt *Link, lib *Library) {
}
defer f.Close()
var magbuf [len(ARMAG)]byte
if _, err := io.ReadFull(f, magbuf[:]); err != nil {
Exitf("file %s too short", lib.File)
}
if string(magbuf[:]) != ARMAG {
Exitf("%s is not an archive file", lib.File)
}
var arhdr ArHdr
l := nextar(f, int64(len(ARMAG)), &arhdr)
l := nextar(f, f.Offset(), &arhdr)
if l <= 0 {
Errorf(nil, "%s: short read on archive file symbol header", lib.File)
return