Maxim has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/84101?usp=email )
Change subject: util/hda-decoder: Protect 'fields' slice if empty string ......................................................................
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 max.senia.poliak@gmail.com --- M util/hda-decoder/main.go 1 file changed, 13 insertions(+), 12 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/01/84101/1
diff --git a/util/hda-decoder/main.go b/util/hda-decoder/main.go index 83ddcbb..c1a1b13 100644 --- a/util/hda-decoder/main.go +++ b/util/hda-decoder/main.go @@ -68,19 +68,20 @@ scanner := bufio.NewScanner(file)
for scanner.Scan() { - fields := strings.Fields(scanner.Text()) - pin := stringToUint32(fields[0]) - config := stringToUint32(fields[1]) + if fields := strings.Fields(scanner.Text()); len(fields) == 2 { + pin := stringToUint32(fields[0]) + config := stringToUint32(fields[1])
- indentedPrintf("AZALIA_PIN_CFG(%d, 0x%02x, ", codec, pin) - if decoder.PortIsConnected(config) { - fmt.Printf("AZALIA_PIN_DESC(\n") - indentLevel += 1 - decodeConfig(config) - indentLevel -= 1 - indentedPrintf(")),\n") - } else { - printDisconnectedPort(config) + indentedPrintf("AZALIA_PIN_CFG(%d, 0x%02x, ", codec, pin) + if decoder.PortIsConnected(config) { + fmt.Printf("AZALIA_PIN_DESC(\n") + indentLevel += 1 + decodeConfig(config) + indentLevel -= 1 + indentedPrintf(")),\n") + } else { + printDisconnectedPort(config) + } } } }