diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2025-04-14 16:07:15 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2025-04-15 11:46:04 +0000 |
| commit | b7285264646c21702afa7317ed90a0d6c06814f8 (patch) | |
| tree | 341fb1bea72994fb800a62b79755dc89eaf078ff /pkg | |
| parent | 9b260b0e8a71a22a5fee1bfe673ecc134f6fc4df (diff) | |
tools/syz-declextract: ignore files with non US-ASCII chars
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/ast/scanner.go | 22 | ||||
| -rw-r--r-- | pkg/ast/testdata/errors.txt | 2 | ||||
| -rw-r--r-- | pkg/declextract/fileops.go | 7 |
3 files changed, 22 insertions, 9 deletions
diff --git a/pkg/ast/scanner.go b/pkg/ast/scanner.go index 9a5becf1c..67dd80e52 100644 --- a/pkg/ast/scanner.go +++ b/pkg/ast/scanner.go @@ -221,14 +221,11 @@ func (s *scanner) scanStr(pos Pos) string { } } lit := string(s.data[pos.Off+1 : s.off]) - for i := 0; i < len(lit); i++ { - if lit[i] < 0x20 || lit[i] >= 0x80 { - pos1 := pos - pos1.Col += i + 1 - pos1.Off += i + 1 - s.Errorf(pos1, "illegal character %#U in string literal", lit[i]) - break - } + if i := IsValidStringLit(lit); i >= 0 { + pos1 := pos + pos1.Col += i + 1 + pos1.Off += i + 1 + s.Errorf(pos1, "illegal character %#U in string literal %q", lit[i], lit) } s.next() if closing != '`' { @@ -352,3 +349,12 @@ func (s *scanner) pos() Pos { Col: s.col, } } + +func IsValidStringLit(lit string) int { + for i := 0; i < len(lit); i++ { + if lit[i] < 0x20 || lit[i] >= 0x80 { + return i + } + } + return -1 +} diff --git a/pkg/ast/testdata/errors.txt b/pkg/ast/testdata/errors.txt index a8a4aa197..0d8488134 100644 --- a/pkg/ast/testdata/errors.txt +++ b/pkg/ast/testdata/errors.txt @@ -20,7 +20,7 @@ int_flags4 = 1, -2- ### bad integer "-2-" str_flags0 = "foo", "bar" str_flags1 = "non terminated ### string literal is not terminated -str_flags2 = "bad chars здесь" ### illegal character U+00D0 'Ð' in string literal +str_flags2 = "bad chars здесь" ### illegal character U+00D0 'Ð' in string literal "bad chars здесь" str_flags3 = "string", not a string ### unexpected identifier, expecting '\n' str_flags4 = "string", 42 ### unexpected int, expecting string, hex string, identifier str_flags5 = `x` ### bad hex string literal: encoding/hex: invalid byte: U+0078 'x' diff --git a/pkg/declextract/fileops.go b/pkg/declextract/fileops.go index 3a82d13c2..8b2ea629a 100644 --- a/pkg/declextract/fileops.go +++ b/pkg/declextract/fileops.go @@ -7,6 +7,8 @@ import ( "fmt" "slices" "strings" + + "github.com/google/syzkaller/pkg/ast" ) const ( @@ -179,6 +181,11 @@ func (ctx *context) mapFopsToFiles(uniqueFuncs map[*Function]int) map[*FileOps][ ctx.FileOps = append(ctx.FileOps, generic) fopsToFiles := make(map[*FileOps][]string) for _, file := range ctx.probe.Files { + // There is a single non US-ASCII file in sysfs: "/sys/bus/pci/drivers/CAFÉ NAND". + // Ignore it for now as descriptions shouldn't contain non US-ASCII chars. + if ast.IsValidStringLit(file.Name) >= 0 { + continue + } // For each file figure out the potential file_operations that match this file best. best := ctx.mapFileToFops(fileToFuncs[file.Name], funcToFops, uniqueFuncs, generic) for _, fops := range best { |
