Skip to content

Commit 5d7b6ef

Browse files
author
Ethan Graham
committed
pkg/kfuzztest: add more types to builder
1 parent 850f466 commit 5d7b6ef

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

pkg/kfuzztest/builder.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package kfuzztest
44

55
import (
66
"fmt"
7+
"regexp"
78
"strings"
89

910
"github.com/google/syzkaller/pkg/ast"
@@ -63,6 +64,8 @@ func (b *Builder) EmitSyzlangDescription() (string, error) {
6364
}
6465
}
6566

67+
fmt.Println(descBuilder.String())
68+
6669
// Format the output syzlang descriptions.
6770
var astError error
6871
eh := func(pos ast.Pos, msg string) {
@@ -163,6 +166,15 @@ func syzConstraintToSyzlang(c SyzConstraint) string {
163166
}
164167
}
165168

169+
func isArray(typeName string) (bool, string) {
170+
re := regexp.MustCompile(`^\[(\d+)\]([a-zA-Z]+)$`)
171+
matches := re.FindStringSubmatch(typeName)
172+
if len(matches) == 0 {
173+
return false, ""
174+
}
175+
return true, fmt.Sprintf("array[%s, %s]", dwarfToSyzlangType(matches[2]), matches[1])
176+
}
177+
166178
func dwarfToSyzlangType(typeName string) string {
167179
if after, ok := strings.CutPrefix(typeName, "struct "); ok {
168180
return after
@@ -174,18 +186,23 @@ func dwarfToSyzlangType(typeName string) string {
174186
return fmt.Sprintf("ptr[inout, %s]", after)
175187
}
176188

189+
isArr, arr := isArray(typeName)
190+
if isArr {
191+
return arr
192+
}
193+
177194
switch typeName {
178-
case "long unsigned int", "size_t":
195+
case "long unsigned int", "long int", "size_t":
179196
return "int64"
180-
case "int":
197+
case "int", "unsigned int":
181198
return "int32"
182199
case "char":
183200
return "int8"
184201
case "__u16":
185202
return "int16"
186203
case "*const char", "*const void", "*const unsigned char":
187204
return "ptr[in, array[int8]]" // const pointers are read-only
188-
case "*char":
205+
case "*char", "*void":
189206
return "ptr[inout, array[int8]]"
190207
default:
191208
return typeName

0 commit comments

Comments
 (0)