capi-sensor: add a checking index of internal sensor type 97/54897/1
authorkibak.yoon <kibak.yoon@samsung.com>
Fri, 18 Dec 2015 11:42:15 +0000 (20:42 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Fri, 18 Dec 2015 11:47:54 +0000 (20:47 +0900)
Change-Id: I8c77cddaf149e6de6b72f04815df91358bedf6ea
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/sensor.cpp

index fd06fc6..128f822 100644 (file)
@@ -105,6 +105,13 @@ static int sensor_connect (sensor_h sensor, sensor_listener_h listener)
 
 static sensor_type_t _sensor_type_to_internal_type(sensor_type_e type)
 {
+       int size;
+       size = sizeof(_TYPE) / sizeof(sensor_type_t);
+
+       if (type >= size) {
+               _E("Failed to change internal type: type[%d]", type);
+               return UNKNOWN_SENSOR;
+       }
        return (type == SENSOR_ALL) ? ALL_SENSOR : _TYPE[type];
 }
 
@@ -124,6 +131,9 @@ int sensor_is_supported(sensor_type_e type, bool *supported)
 
        internal_type = _sensor_type_to_internal_type(type);
 
+       if (internal_type == UNKNOWN_SENSOR)
+               return SENSOR_ERROR_INVALID_PARAMETER;
+
        sensor = sensord_get_sensor(internal_type);
        _supported = false;
 
@@ -154,6 +164,9 @@ int sensor_get_default_sensor(sensor_type_e type, sensor_h *sensor)
 
        internal_type = _sensor_type_to_internal_type(type);
 
+       if (internal_type == UNKNOWN_SENSOR)
+               return SENSOR_ERROR_INVALID_PARAMETER;
+
        _sensor = sensord_get_sensor(internal_type);
 
        if (!_sensor)
@@ -187,6 +200,9 @@ int sensor_get_sensor_list(sensor_type_e type, sensor_h **list, int *sensor_coun
 
        internal_type = _sensor_type_to_internal_type(type);
 
+       if (internal_type == UNKNOWN_SENSOR)
+               return SENSOR_ERROR_INVALID_PARAMETER;
+
        sensord_get_sensor_list(internal_type, &_list, &count);
 
        if (count == 0)