summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Aksenov <a.aksenov@samsung.com>2016-12-07 19:25:27 +0300
committerDmitry Kovalenko <d.kovalenko@samsung.com>2016-12-09 04:19:38 -0800
commit512a81b7118e5f2e0e3bc48b62dc40a6deb74084 (patch)
tree128c738a80ec6ae31e753f6a8d14679f1d1d7406
parent65eb287136b61568e4d80b2abbd40de703e217e8 (diff)
downloadswap-manager-512a81b7118e5f2e0e3bc48b62dc40a6deb74084.tar.gz
swap-manager-512a81b7118e5f2e0e3bc48b62dc40a6deb74084.tar.bz2
swap-manager-512a81b7118e5f2e0e3bc48b62dc40a6deb74084.zip
UIHV: Fix data_buf initialization
Previously data_buf was NULL for log.length > 0 && log.length < sizeof(log.data) Svace issue. Change-Id: I74004cef90c2c7b05397af3b7256292a07928e85 Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
-rw-r--r--ui_viewer/ui_viewer_lib.c71
1 files changed, 41 insertions, 30 deletions
diff --git a/ui_viewer/ui_viewer_lib.c b/ui_viewer/ui_viewer_lib.c
index 5ebfbbd..280c398 100644
--- a/ui_viewer/ui_viewer_lib.c
+++ b/ui_viewer/ui_viewer_lib.c
@@ -316,6 +316,33 @@ free_data_buf:
return ret;
}
+/* Allocate memory and gets payload for message */
+static char *get_msg_payload(log_t *log)
+{
+ char *data_buf = NULL;
+ ssize_t recvlen;
+
+ if (log->length <= 0)
+ return NULL;
+
+ data_buf = malloc(log->length);
+ if (data_buf == NULL) {
+ PRINTERR("Cannot allocate buffer for message. Size %d",
+ log->length);
+ return NULL;
+ }
+
+ recvlen = recv(gTraceInfo.socket.daemonSock, data_buf, log->length,
+ MSG_WAITALL);
+ if (recvlen != log->length) {
+ PRINTERR("Cannot receive data!");
+ free(data_buf);
+ data_buf = NULL;
+ }
+
+ return data_buf;
+}
+
static void *recvThread(void __unused *data)
{
fd_set readfds, workfds;
@@ -373,36 +400,21 @@ static void *recvThread(void __unused *data)
if(recvlen > 0) // recv succeed
{
-
- if (log.length > 0 &&
- (unsigned int)log.length <= sizeof(log.data)) {
- data_buf = malloc(log.length);
- if (data_buf == NULL) {
- PRINTERR("cannot allocate buf to recv msg");
- break;
- }
- recvlen = recv(gTraceInfo.socket.daemonSock, data_buf,
- log.length, MSG_WAITALL);
- if (recvlen != log.length) {
- PRINTERR("Can not recv data from\n");
+ if (log.type == APP_MSG_CONFIG) {
+ data_buf = get_msg_payload(&log);
+ if (data_buf != NULL) {
+ _configure(data_buf);
goto free_data_buf;
}
- }
-
- if (log.type == APP_MSG_CONFIG) {
- _configure(data_buf);
} else if(log.type == APP_MSG_STOP) {
PRINTMSG("APP_MSG_STOP");
- if (data_buf) {
- free(data_buf);
- data_buf = NULL;
- }
application_exit();
break;
} else if(log.type == APP_MSG_TYPE_AND_INFO) {
PRINTMSG("APP_MSG_TYPE_AND_INFO");
} else if(log.type == APP_MSG_GET_UI_HIERARCHY) {
enum ErrorCode err_code = ERR_UNKNOWN;
+ Eina_Bool rendering;
print_log_ui_viewer_hierarchy_status(&err_code);
@@ -411,12 +423,12 @@ static void *recvThread(void __unused *data)
continue;
}
- if(log.length > 0) {
- Eina_Bool rendering;
-
- rendering = (enum rendering_option_t)*((uint8_t *)data_buf);
+ rendering = (enum rendering_option_t)
+ *((uint8_t *)get_msg_payload(&log));
+ if(rendering != 0) {
PRINTMSG("APP_MSG_GET_UI_HIERARCHY, rendering option <%d>", rendering);
ecore_set_data_get_uihv(rendering);
+ goto free_data_buf;
} else {
PRINTERR("WRONG APP_MSG_GET_UI_PROPERTIES");
}
@@ -427,12 +439,14 @@ static void *recvThread(void __unused *data)
set_hierarchy_status(HIERARCHY_CANCELLED);
continue;
} else if(log.type == APP_MSG_GET_UI_SCREENSHOT) {
- if(log.length > 0) {
- Evas_Object *obj;
+ Evas_Object *obj;
+ obj = (Evas_Object*)(unsigned long)
+ *((uint64_t *)get_msg_payload(&log));
+ if(obj != 0) {
- obj = (Evas_Object*)(unsigned long)*((uint64_t *)data_buf);
PRINTMSG("APP_MSG_GET_UI_SCREENSHOT <0x%lx>", obj);
ecore_set_data_get_obj_screenshot(obj);
+ goto free_data_buf;
} else {
PRINTERR("WRONG APP_MSG_GET_UI_SCREENSHOT");
}
@@ -467,8 +481,5 @@ free_data_buf:
}
}
- if (data_buf)
- free(data_buf);
-
return NULL;
}