]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: check magic header
authorHiroshi Ioka <hirochachacha@gmail.com>
Tue, 25 Jul 2017 02:34:30 +0000 (11:34 +0900)
committerIan Lance Taylor <iant@golang.org>
Fri, 11 Aug 2017 01:51:34 +0000 (01:51 +0000)
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>

src/cmd/link/internal/ld/ar.go
src/cmd/link/internal/ld/lib.go

index 8827b76aedf7ae8f4851e74e5e1b19f3f0457a79..c8115a67d7690d7582c585b1b6a6572d491d7963 100644 (file)
@@ -82,6 +82,10 @@ func hostArchive(ctxt *Link, name string) {
                Exitf("file %s too short", name)
        }
 
+       if string(magbuf[:]) != ARMAG {
+               Exitf("%s is not an archive file", name)
+       }
+
        var arhdr ArHdr
        l := nextar(f, f.Offset(), &arhdr)
        if l <= 0 {
index 023410512c9d1bdcec776513646eb4238fe18123..995562803892d1977ed884fb7a516bdab945636b 100644 (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