From bac98417ca282e1ac0b41a03e178bda6a93f6c94 Mon Sep 17 00:00:00 2001 From: mahai Date: Tue, 12 Jul 2022 19:03:54 +0800 Subject: [PATCH] fix:Modify function parameter overflow risk Signed-off-by: mahai --- khdf/liteos/platform/src/gpio_dev.c | 5 +++++ khdf/liteos/platform/src/uart_dev.c | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/khdf/liteos/platform/src/gpio_dev.c b/khdf/liteos/platform/src/gpio_dev.c index 196efc0..d9bdd40 100644 --- a/khdf/liteos/platform/src/gpio_dev.c +++ b/khdf/liteos/platform/src/gpio_dev.c @@ -104,6 +104,11 @@ static int GpioIoctl(struct file *filep, int cmd, unsigned long arg) struct GpioBitInfo info = {0}; struct drv_data *drvData = NULL; + if (arg == 0) { + HDF_LOGE("%s arg is 0", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (filep == NULL || filep->f_vnode == NULL || filep->f_vnode->data == NULL) { HDF_LOGE("%s: function parameter is null", __func__); return HDF_ERR_INVALID_PARAM; diff --git a/khdf/liteos/platform/src/uart_dev.c b/khdf/liteos/platform/src/uart_dev.c index dd4d560..a0215bc 100644 --- a/khdf/liteos/platform/src/uart_dev.c +++ b/khdf/liteos/platform/src/uart_dev.c @@ -37,6 +37,7 @@ #define HDF_LOG_TAG hdf_uart_dev #define HDF_UART_FS_MODE 0660 +#define ARG_MAX_RANG 0xFFFFFFFF static int32_t UartDevOpen(struct file *filep) { @@ -145,6 +146,12 @@ static int32_t UartDevIoctl(struct file *filep, int32_t cmd, unsigned long arg) { int32_t ret = HDF_FAILURE; struct UartHost *host = NULL; + + if (arg == 0) { + HDF_LOGE("%s arg is 0", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (filep == NULL || filep->f_vnode == NULL) { return HDF_ERR_INVALID_PARAM; } @@ -153,6 +160,11 @@ static int32_t UartDevIoctl(struct file *filep, int32_t cmd, unsigned long arg) switch (cmd) { case UART_CFG_BAUDRATE: + if (arg > ARG_MAX_RANG) { + HDF_LOGE("%s arg out of range", __func__); + ret = HDF_ERR_INVALID_PARAM; + break; + } ret = UartHostSetBaud(host, arg); break; case UART_CFG_RD_BLOCK: -- Gitee