Fix static analysis issue 58/128258/2 accepted/tizen/unified/20170510.013102 submit/tizen/20170508.093623 tizen_4.0.m1_release
authorHyeongsik Min <hyeongsik.min@samsung.com>
Mon, 8 May 2017 07:57:34 +0000 (16:57 +0900)
committerHyeongsik Min <hyeongsik.min@samsung.com>
Mon, 8 May 2017 08:48:00 +0000 (17:48 +0900)
- UNREACHABLE_CODE at peripheral_bus_gpio.c:254
- INTEGER_OVERFLOW in adc_get_device_name()
  This patch makes the function allocate buffer for the name of adc device
  node instead of just copying strings to buffer passed through argument.

Change-Id: If5d137a846ca5727b3d2cb00f4a2b6d313abf75f
Signed-off-by: Hyeongsik Min <hyeongsik.min@samsung.com>
src/daemon/peripheral_bus_gpio.c
src/interface/adc.c
src/interface/include/adc.h

index b49a202..c7ca9b8 100644 (file)
@@ -21,7 +21,6 @@
 #include <peripheral_io.h>
 
 #include "gpio.h"
-#include "peripheral_io_gdbus.h"
 #include "peripheral_bus.h"
 #include "peripheral_common.h"
 
@@ -251,7 +250,7 @@ int peripheral_bus_gpio_write(gint pin, gint value, gpointer user_data)
                return ret;
        }
        /* Update direction state along with the value */
-       gpio->direction = GPIO_DIRECTION_OUT + (value > 0) ? 1 : 0;
+       gpio->direction = GPIO_DIRECTION_OUT + ((value > 0) ? 1 : 0);
 
        return PERIPHERAL_ERROR_NONE;
 }
index 93f7797..e99b8e3 100644 (file)
 #define PATH_BUF_MAX           64
 #define ADC_BUF_MAX                    16
 
-int adc_get_device_name(char *devName)
+int adc_get_device_name(char **dev_name)
 {
        int fd;
-       int device = 0; /* for get adc device name, /sys/bus/iio/devices/iio:device"0" */
-       char fName[PATH_BUF_MAX] = {0};
+       int device = 0;
        int bytes;
+       char buf[PATH_BUF_MAX];
 
-       snprintf(fName, PATH_BUF_MAX, "%s%d%s", SYSFS_ADC_PATH, device, "/name");
-       if ((fd = open(fName, O_RDONLY)) < 0) {
-               _E("Error[%d]: can't open adc device name, %s--[%d]\n", errno, __FUNCTION__, __LINE__);
+       snprintf(buf, PATH_BUF_MAX, "%s%d%s", SYSFS_ADC_PATH, device, "/name");
+       if ((fd = open(buf, O_RDONLY)) < 0) {
+               _E("Cannot open %s, errno : %d", buf, errno);
                return -ENODEV;
        }
-       bytes = read(fd, devName, PATH_BUF_MAX);
-       if (bytes == -1) {
+
+       if ((bytes = read(fd, buf, PATH_BUF_MAX)) == -1) {
+               _E("Cannot read %s, errno : %d", buf, errno);
                close(fd);
                return -EIO;
        }
 
-       devName[strlen(devName) - 1] = '\0';
+       *dev_name = strndup(buf, PATH_BUF_MAX);
        close(fd);
 
        return 0;
index 1d54f2a..2531db2 100644 (file)
 /**
 * @brief adc_init() find adc device name.
 *
-* @param[in] *devName adc device name
+* @param[out] dev_name The name of adc device node which must be freed.
 * @return On success, 0 is returned. On failure, a negative value is returned.
 */
-int adc_get_device_name(char *devName);
+int adc_get_device_name(char **dev_name);
 
 /**
 * @brief adc_get_data() get adc data.