From 54a701ada1f06620a9c1c97220033d76a81d6f28 Mon Sep 17 00:00:00 2001 From: Jan Hoffmann Date: Tue, 10 Oct 2023 22:02:15 +0200 Subject: [PATCH] Fix possible out of range slice access in DrayTek client The bitloading and SNR data slices are initially sized to match the current DSL mode. However, the device may report additional zero values at the end (for example for VDSL2 profile 30a). Ignore those to avoid out of range writes to the data slices. --- draytek/bins.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/draytek/bins.go b/draytek/bins.go index 61faf75..a5efa1c 100644 --- a/draytek/bins.go +++ b/draytek/bins.go @@ -95,15 +95,20 @@ func readShowbinsBin(binsBits *models.BinsBits, snrData []float64, maxSNRIndex, snr, _ := strconv.ParseFloat(data[1], 64) bits, _ := strconv.ParseInt(data[3], 10, 64) - if bits != 0 { - binsBits.Data[num] = int8(bits) - *maxBitsIndex = num + if num < len(binsBits.Data) { + if bits != 0 { + binsBits.Data[num] = int8(bits) + *maxBitsIndex = num + } } - if snr != 0 && snr != -32 { - snrData[num] = snr - *maxSNRIndex = num - } else { - snrData[num] = -32.5 + + if num < len(snrData) { + if snr != 0 && snr != -32 { + snrData[num] = snr + *maxSNRIndex = num + } else { + snrData[num] = -32.5 + } } } }