Linting: buffer size safety 11/260611/2
authorMichal Bloch <m.bloch@samsung.com>
Tue, 29 Jun 2021 18:34:57 +0000 (20:34 +0200)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Wed, 30 Jun 2021 14:00:54 +0000 (14:00 +0000)
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

src/peripheral_gpio.c

index fa9c870..a7c51d4 100644 (file)
@@ -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++) {