atsam: add a length check to findPinPadMapping

Этот коммит содержится в:
sago35 2020-12-02 09:21:38 +09:00 коммит произвёл GitHub
родитель 0c4f0b1ebf
коммит 2540172cc5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 10 добавлений и 0 удалений

Просмотреть файл

@ -136,6 +136,11 @@ var pinPadMapping = [32]byte{
// found" (indicated by returning ok=false). The pad number is returned to
// calculate the DOPO/DIPO bitfields of the various serial peripherals.
func findPinPadMapping(sercom uint8, pin Pin) (pinMode PinMode, pad uint32, ok bool) {
if int(pin)/2 >= len(pinPadMapping) {
// This is probably NoPin, for which no mapping is available.
return
}
nibbles := pinPadMapping[pin/2]
upper := nibbles >> 4
lower := nibbles & 0xf

Просмотреть файл

@ -322,6 +322,11 @@ var pinPadMapping = [64]uint16{
// (indicated by returning ok=false). The pad number is returned to calculate
// the DOPO/DIPO bitfields of the various serial peripherals.
func findPinPadMapping(sercom uint8, pin Pin) (pinMode PinMode, pad uint32, ok bool) {
if int(pin)/2 >= len(pinPadMapping) {
// This is probably NoPin, for which no mapping is available.
return
}
bytes := pinPadMapping[pin/2]
upper := byte(bytes >> 8)
lower := byte(bytes & 0xff)