From: Alexander Aksenov Date: Wed, 7 Dec 2016 16:25:27 +0000 (+0300) Subject: UIHV: Fix data_buf initialization X-Git-Tag: accepted/tizen/3.0/common/20161213.163342~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=512a81b7118e5f2e0e3bc48b62dc40a6deb74084;p=platform%2Fcore%2Fsystem%2Fswap-manager.git 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 --- 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; }