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)
{
// 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;