From 7f68483e281562f46f61304bc84efbd5fd5faf1b Mon Sep 17 00:00:00 2001 From: Maxim Polyakov Date: Tue, 27 Aug 2024 17:08:39 +0300 Subject: [PATCH] util/hda-decoder: Protect 'fields' slice if empty string This avoids panic if the file contains an empty string or an incorrect configuration: goroutine 1 [running]: main.decodeFile({0x7ffd63da92a0?, 0xc000014070?}, 0x8?) /path/to/coreboot/util/hda-decoder/main.go:72 +0x2ef main.main() /path/to/coreboot/util/hda-decoder/main.go:158 +0x2a5 Change-Id: I9ae8544e52d82e8d8a82a88a85a2de7d2f295ec1 Signed-off-by: Maxim Polyakov Reviewed-on: https://review.coreboot.org/c/coreboot/+/84101 Reviewed-by: Felix Singer Tested-by: build bot (Jenkins) Reviewed-by: Angel Pons --- util/hda-decoder/main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/hda-decoder/main.go b/util/hda-decoder/main.go index 83ddcbb43a..d686f19967 100644 --- a/util/hda-decoder/main.go +++ b/util/hda-decoder/main.go @@ -69,6 +69,11 @@ func decodeFile(path string, codec uint32) { for scanner.Scan() { fields := strings.Fields(scanner.Text()) + if len(fields) != 2 { + fmt.Print("// Something went wrong\n") + continue + } + pin := stringToUint32(fields[0]) config := stringToUint32(fields[1])