mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/link: fix export data truncation bug
Similar fix as in CL 60773 for fixing cmd/pack. Fixes #21703. Change-Id: I457ed8a3be828fd458abc5c8c1cc766a9f7aab13 Reviewed-on: https://go-review.googlesource.com/79135 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
f100e0c228
commit
5e423ed855
2 changed files with 61 additions and 3 deletions
|
|
@ -1474,13 +1474,29 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string,
|
|||
}
|
||||
}
|
||||
|
||||
/* skip over exports and other info -- ends with \n!\n */
|
||||
// Skip over exports and other info -- ends with \n!\n.
|
||||
//
|
||||
// Note: It's possible for "\n!\n" to appear within the binary
|
||||
// package export data format. To avoid truncating the package
|
||||
// definition prematurely (issue 21703), we keep keep track of
|
||||
// how many "$$" delimiters we've seen.
|
||||
|
||||
import0 := f.Offset()
|
||||
|
||||
c1 = '\n' // the last line ended in \n
|
||||
c2 = bgetc(f)
|
||||
c3 = bgetc(f)
|
||||
for c1 != '\n' || c2 != '!' || c3 != '\n' {
|
||||
markers := 0
|
||||
for {
|
||||
if c1 == '\n' {
|
||||
if markers%2 == 0 && c2 == '!' && c3 == '\n' {
|
||||
break
|
||||
}
|
||||
if c2 == '$' && c3 == '$' {
|
||||
markers++
|
||||
}
|
||||
}
|
||||
|
||||
c1 = c2
|
||||
c2 = c3
|
||||
c3 = bgetc(f)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue