return id;
}
-static int __get_int_from_str(const char *str)
+static bool __get_int_from_str(const char *str, int *trans_value)
{
- int result = 0;
+ long result = 0;
char *pend;
errno = 0;
result = strtol(str, &pend, 10);
- if ((result == LONG_MIN || result == LONG_MAX)
- && errno != 0) {
- result = 0;
+ if (result < INT_MIN || result > INT_MAX || errno != 0) {
+ _LOGE("strtol failed :%s [%d]", str, errno);
+ return false;
}
- if (*pend != '\0')
- result = 0;
+ if (*pend != '\0') {
+ _LOGE("strtol failed : %s, %s ", str, pend);
+ return false;
+ }
+ *trans_value = (int)result;
- return result;
+ return true;
}
static bundle *__get_bundle_data_from_fd(int fd)
_LOGI("page num: %s, count_per_page: %s, value_count %s",
page_num_str, count_per_page_str, value_count_str);
- if (page_num_str)
- page_number = __get_int_from_str(page_num_str);
- if (count_per_page_str)
- count_per_page = __get_int_from_str(count_per_page_str);
- if (value_count_str)
- value_count = __get_int_from_str(value_count_str);
+ if (!page_num_str || !count_per_page_str || !value_count_str) {
+ _LOGE("bundle was corrupted.");
+ return DATA_CONTROL_ERROR_IO_ERROR;
+ }
+
+ if (!__get_int_from_str(page_num_str, &page_number))
+ return DATA_CONTROL_ERROR_IO_ERROR;
+
+ if (page_number < 1) {
+ _LOGE("bundle was corrupted. page_number[%d]", page_number);
+ return DATA_CONTROL_ERROR_IO_ERROR;
+ }
+
+ if (!__get_int_from_str(count_per_page_str, &count_per_page))
+ return DATA_CONTROL_ERROR_IO_ERROR;
+
+ if (!__get_int_from_str(value_count_str, &value_count))
+ return DATA_CONTROL_ERROR_IO_ERROR;
current_offset = (page_number - 1) * count_per_page;
remain_count = value_count - current_offset;
char *provider_id;
char *caller_appid;
bundle *value = NULL;
+ int i = 1;
+ int current = 0;
+ int column_count;
const char *request_type =
bundle_get_val(b, OSP_K_DATACONTROL_REQUEST_TYPE);
switch (type) {
case DATACONTROL_TYPE_SQL_SELECT:
{
- int i = 1;
- int current = 0;
- int column_count = __get_int_from_str(arg_list[i++]); /* Column count */
+ if (!__get_int_from_str(arg_list[i++], &column_count)) { /* Column count */
+ _LOGE("Failed to convert column_count", column_count);
+ goto err;
+ }
if (column_count <= 0 || column_count > MAX_COLUMN_COUNT) {
_LOGE("Invalid column count %d", column_count);
bundle *b;
const char *page_num_str;
const char *count_per_page_str;
+ int result;
if (__request_table == NULL) {
_LOGE("__request_table is NULL");
_LOGE("No page data for the request id: %d, ", request_id);
return DATA_CONTROL_ERROR_INVALID_PARAMETER;
}
- *page_num = __get_int_from_str(page_num_str);
- *count_per_page = __get_int_from_str(count_per_page_str);
+ if (!__get_int_from_str(page_num_str, &result)) {
+ _LOGE("Failed to convert page_num_str", page_num_str);
+ return DATA_CONTROL_ERROR_IO_ERROR;
+ }
+ *page_num = result;
+
+ if (!__get_int_from_str(count_per_page_str, &result)) {
+ _LOGE("Failed to convert count_per_page_str", count_per_page_str);
+ return DATA_CONTROL_ERROR_IO_ERROR;
+ }
+ *count_per_page = result;
return DATA_CONTROL_ERROR_NONE;
}