From d05fac390ea1ef6bcf7bb897839e5ea569ac9d1a Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 18 Dec 2015 20:42:15 +0900 Subject: [PATCH] capi-sensor: add a checking index of internal sensor type Change-Id: I8c77cddaf149e6de6b72f04815df91358bedf6ea Signed-off-by: kibak.yoon --- src/sensor.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/sensor.cpp b/src/sensor.cpp index fd06fc6..128f822 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -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) -- 2.34.1