drivers: gpio: Validate pin number before indexing array in mcux drivers

Validates the gpio pin number before using it to index into a
memory-mapped register array. Otherwise, a user could send a high pin
number and cause an out-of-bounds access.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
This commit is contained in:
Maureen Helm 2019-01-30 16:52:34 -06:00 committed by Kumar Gala
commit 3c44137447
2 changed files with 10 additions and 0 deletions

View file

@ -38,6 +38,11 @@ static int gpio_mcux_configure(struct device *dev,
u32_t pcr = 0U;
u8_t i;
/* Check for an invalid pin number */
if (pin >= ARRAY_SIZE(port_base->PCR)) {
return -EINVAL;
}
/* Check for an invalid pin configuration */
if ((flags & GPIO_INT) && (flags & GPIO_DIR_OUT)) {
return -EINVAL;