From e0199c925b570db5ca28c1b463aa8b506e0d9bb5 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Tue, 26 Sep 2017 16:23:29 +0300 Subject: [PATCH] lsan: use the swap_auxd for report saving Change-Id: I6aad791b0fe3daee8227cf9c0b8b802c08ddcfe2 Signed-off-by: Vyacheslav Cherkashin --- daemon/threads.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/daemon/threads.c b/daemon/threads.c index a30ebac..d07a9bb 100644 --- a/daemon/threads.c +++ b/daemon/threads.c @@ -70,6 +70,99 @@ static int save_data_to_tmpfile(char *path, int suffixlen, return 0; } +static char *get_path_by_report(void *data, size_t size, size_t path_offset) +{ + const size_t max_buf_size = size - path_offset; + char *path = data + path_offset; + size_t path_len; + + if (path_offset >= size) + return NULL; + + path_len = strnlen(path, max_buf_size); + if (path_len == max_buf_size) + return NULL; + + return path; +} + +static void processing_app_msg_lsan_report(void *data, size_t len) +{ + void *data_end = data + len; + void *report_msg, *report_data; + uint32_t report_msg_size, report_size, path_offset; + char *path; + + + /* + * get report_msg_size + */ + if (data + 4 >= data_end) { + LOGE("Message is very small\n"); + return; + } + report_msg_size = *(uint32_t *)data; + data += 4; + + + /* + * get report_msg + */ + report_msg = data; + data += report_msg_size; + + + /* + * get path_offset + */ + if (data + 4 >= data_end) { + LOGE("Incorrect data\n"); + return; + } + path_offset = *(uint32_t *)data; + data += 4; + + if (path_offset >= report_msg_size) { + LOGE("Incorrect report_offset\n"); + return; + } + + + /* + * get report_size + */ + if (data + 4 >= data_end) { + LOGE("Incorrect data\n"); + return; + } + report_size = *(uint32_t *)data; + data += 4; + + + /* + * get report_data + */ + report_data = data; + data += report_size; + + if (data != data_end) { + LOGE("Incorrect data\n"); + return; + } + + + path = get_path_by_report(report_msg, report_msg_size, path_offset); + if (!save_data_to_tmpfile(path, 0, report_data, report_size)) { + LOGI("Save LSAN report to '%s'\n", path); + + struct msg_data_t *msg = (struct msg_data_t *)report_msg; + if (write_to_buf(msg) != 0) + LOGE("write to buf fail\n"); + } else { + LOGE("Cannot save LSAN report to '%s'\n", path); + } +} + static void send_screenshot_msg(const char *path, uint32_t angle, const char *sh_info, size_t sh_info_len) { @@ -336,6 +429,9 @@ static void* recvThread(void* data) // don't send to host LOGW("EXTRA '%s'\n", msg->data); continue; + } else if (msg->type == APP_MSG_LSAN_REPORT) { + processing_app_msg_lsan_report(msg->data, msg->length); + continue; } else if (msg->type == APP_MSG_IMAGE) { processing_app_msg_image(msg->data, msg->length); continue; -- 2.7.4