From: Michal Bloch Date: Tue, 29 Jun 2021 18:34:57 +0000 (+0200) Subject: Linting: buffer size safety X-Git-Tag: submit/tizen/20210705.023617~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F11%2F260611%2F2;p=platform%2Fcore%2Fapi%2Fperipheral-io.git Linting: buffer size safety Make sure the buffer's actual size is used. This safeguards against somebody changing the size of the buffer but forgetting to change the value that gets passed as its size to other functions. Change-Id: I12c78acf56daf55a785e9c994ca70ed34a38a1de --- diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index fa9c870..a7c51d4 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -184,7 +184,7 @@ static int peripheral_gpio_set_initial_direction_into_handle(peripheral_gpio_h g char gpio_buf[GPIO_BUFFER_MAX] = {0, }; - int ret = read(gpio->fd_direction, &gpio_buf, GPIO_BUFFER_MAX); + int ret = read(gpio->fd_direction, &gpio_buf, sizeof gpio_buf); CHECK_ERROR(ret <= 0); for (size_t index = 0; index < ARRAY_SIZE(types); index++) { @@ -219,7 +219,7 @@ static int peripheral_gpio_set_initial_edge_into_handle(peripheral_gpio_h gpio) char gpio_buf[GPIO_BUFFER_MAX] = {0, }; - int ret = read(gpio->fd_edge, &gpio_buf, GPIO_BUFFER_MAX); + int ret = read(gpio->fd_edge, &gpio_buf, sizeof gpio_buf); CHECK_ERROR(ret <= 0); for (size_t index = 0; index < ARRAY_SIZE(types); index++) {