aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-06-13 19:34:23 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-06-13 19:56:20 +0200
commit3637706c077cb67c46e889fa3367740173028b59 (patch)
tree5442157924529495fd381dbcd875dae199601c19
parenta9bc67ccc6bc5239ecf2753817f8f7c423caa5c6 (diff)
tools/syz-check: fix bug with struct name overwrite
We patched name in struct object, but the dwarf package caches then and then can return in subsequent invocations. This causes a struct name to be overwritten by typedef name. Don't mutate returned struct objects.
-rw-r--r--tools/syz-check/dwarf.go28
1 files changed, 16 insertions, 12 deletions
diff --git a/tools/syz-check/dwarf.go b/tools/syz-check/dwarf.go
index 4acd78dbe..d3e1adb12 100644
--- a/tools/syz-check/dwarf.go
+++ b/tools/syz-check/dwarf.go
@@ -43,7 +43,7 @@ func parseKernelObject(obj string) (map[string]*dwarf.StructType, error) {
buffer := 100 * numProcs
unitc := make(chan Unit, buffer)
offsetc := make(chan []dwarf.Offset, buffer)
- structc := make(chan []*dwarf.StructType, buffer)
+ structc := make(chan map[string]*dwarf.StructType, buffer)
errc := make(chan error)
go extractCompilationUnits(debugInfo, unitc, errc)
@@ -87,8 +87,8 @@ func parseKernelObject(obj string) (map[string]*dwarf.StructType, error) {
result := make(map[string]*dwarf.StructType)
go func() {
for structs := range structc {
- for _, str := range structs {
- result[str.StructName] = str
+ for name, str := range structs {
+ result[name] = str
}
}
errc <- nil
@@ -164,7 +164,7 @@ func extractOffsets(debugInfo *dwarf.Data, unitc chan Unit, offsetc chan []dwarf
}
func extractStructs(file *elf.File, debugInfo *dwarf.Data, offsetc chan []dwarf.Offset,
- structc chan []*dwarf.StructType, errc chan error) {
+ structc chan map[string]*dwarf.StructType, errc chan error) {
if debugInfo == nil {
var err error
debugInfo, err = file.DWARF()
@@ -173,11 +173,15 @@ func extractStructs(file *elf.File, debugInfo *dwarf.Data, offsetc chan []dwarf.
return
}
}
- var structs []*dwarf.StructType
- appendStruct := func(str *dwarf.StructType) {
- if str.StructName != "" && str.ByteSize > 0 {
- structs = append(structs, str)
+ var structs map[string]*dwarf.StructType
+ appendStruct := func(str *dwarf.StructType, name string) {
+ if name == "" || str.ByteSize <= 0 {
+ return
+ }
+ if structs == nil {
+ structs = make(map[string]*dwarf.StructType)
}
+ structs[name] = str
}
for offsets := range offsetc {
for _, off := range offsets {
@@ -188,18 +192,18 @@ func extractStructs(file *elf.File, debugInfo *dwarf.Data, offsetc chan []dwarf.
}
switch typ := typ1.(type) {
case *dwarf.StructType:
- appendStruct(typ)
+ appendStruct(typ, typ.StructName)
case *dwarf.TypedefType:
if str, ok := typ.Type.(*dwarf.StructType); ok {
- str.StructName = typ.Name
- appendStruct(str)
+ appendStruct(str, typ.Name)
}
default:
errc <- fmt.Errorf("got not struct/typedef")
+ return
}
}
structc <- structs
- structs = make([]*dwarf.StructType, 0, len(structs))
+ structs = nil
}
errc <- nil
}