Skip to content

Commit

Permalink
Fix possible out of range slice access in DrayTek client
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
janh committed Oct 10, 2023
1 parent 1fda215 commit 54a701a
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions draytek/bins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand Down

0 comments on commit 54a701a

Please sign in to comment.