Skip to content

Commit 3be0cc1

Browse files
committed
debug/elf: guard access to File.gnuVersym
The size of gnuVersym should be multiples of 2. If not, the input is invalid. No Library and Version information is added to sym in this case. The current implementation of gnuVersion does not report errors for invalid input. While at here, bring back the comment that states that the undef entry at the beginning is skipped. This is not an off-by-one error. No test case because the problem can only happen for invalid data. Let the fuzzer find cases like this.
1 parent 939f9fd commit 3be0cc1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/debug/elf/file.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -1570,12 +1570,16 @@ func (f *File) gnuVersionInit(str []byte) bool {
15701570
// gnuVersion adds Library and Version information to sym,
15711571
// which came from offset i of the symbol table.
15721572
func (f *File) gnuVersion(i int) (library string, version string) {
1573-
// Each entry is two bytes.
1573+
// Each entry is two bytes; skip undef entry at beginning.
15741574
i = (i + 1) * 2
15751575
if i >= len(f.gnuVersym) {
15761576
return
15771577
}
1578-
j := int(f.ByteOrder.Uint16(f.gnuVersym[i:]))
1578+
s := f.gnuVersym[i:]
1579+
if len(s) < 2 {
1580+
return
1581+
}
1582+
j := int(f.ByteOrder.Uint16(s))
15791583
if j < 2 || j >= len(f.gnuNeed) {
15801584
return
15811585
}

0 commit comments

Comments
 (0)