[FIX] prevent issue 64/30964/1 vd_sync_28112014
authorVitaliy Cherepanov <v.cherepanov@samsung.com>
Thu, 27 Nov 2014 15:23:37 +0000 (18:23 +0300)
committerVitaliy Cherepanov <v.cherepanov@samsung.com>
Thu, 27 Nov 2014 15:23:37 +0000 (18:23 +0300)
Prevent TV

Change-Id: Iddf2b2b3d3e1275e29d3bdf4f1351507bcc562c4
Signed-off-by: Vitaliy Cherepanov <v.cherepanov@samsung.com>
helper/damaps.c
helper/libdaprobe.c
include/binproto.h
include/damaps.h
probe_event/orientation.c

index 2cff157ffccc3eb16c1064d0d79be6537ae5968c..fdfcd0eb63cebc5bc399cf9a51270f6a7b6af79b 100755 (executable)
@@ -503,6 +503,7 @@ static inline void maps_writer_unlock()
        pthread_mutex_unlock(&maps_lock);
 }
 
+/* TODO refactor this function to alloc map_inst_list_set and copy it frm src*/
 // WARNING! this function use maps_set and set it to NULL
 // so first param must be malloced and do not free maps_set after call
 int set_map_inst_list(char **maps_set, uint32_t maps_count)
@@ -525,16 +526,25 @@ int set_map_inst_list(char **maps_set, uint32_t maps_count)
        }
 
        map_inst_list = real_malloc(sizeof(*map_inst_list) * maps_count);
-       if (maps_set != NULL && *maps_set != NULL)
+       if (maps_count != 0 && map_inst_list == NULL) {
+               PRINTERR("Cannot allocate data for map_inst_list\n");
+               res = -1;
+               goto unlock_exit;
+       }
+
+       if (maps_set != NULL && *maps_set != NULL && map_inst_list != NULL) {
                map_inst_list_set = *maps_set;
-       map_inst_count = maps_count;
-
-       /* add library mapping names */
-       p = map_inst_list_set + sizeof(maps_count);
-       for (i = 0; i < maps_count; i++) {
-               map_inst_list[i] = p;
-               p += strlen(p) + 1;
-               PRINTMSG("-------> %s", map_inst_list[i]);
+               map_inst_count = maps_count;
+
+               /* add library mapping names */
+               p = map_inst_list_set + sizeof(maps_count);
+               for (i = 0; i < maps_count; i++) {
+                       map_inst_list[i] = p;
+                       p += strlen(p) + 1;
+                       PRINTMSG("-------> %s", map_inst_list[i]);
+               }
+       } else {
+               map_inst_count = 0;
        }
 
        res = update_is_instrument_lib_attr_nolock();
@@ -542,14 +552,16 @@ int set_map_inst_list(char **maps_set, uint32_t maps_count)
        if (maps_set != NULL)
                *maps_set = NULL;
 
+unlock_exit:
        maps_reader_unlock_all();
        maps_writer_unlock();
 
        return res;
 }
 
-void maps_make()
+int maps_make()
 {
+       int res = 0;
        maps_writer_lock();
        maps_reader_lock_all();
        FILE *f = fopen("/proc/self/maps", "r");
@@ -572,6 +584,11 @@ void maps_make()
 
        /* add  locations */
        map = (*real_malloc)(sizeof(*map));
+       if (map == NULL) {
+               PRINTERR("Can not alloc data for map\n");
+               res = -1;
+               goto unlock_exit;
+       }
        while (read_mapping_line(f, map)) {
                if (map->permissions[2] == 'x') {
                        map->hash = calc_string_hash(map->filename);
@@ -591,8 +608,11 @@ void maps_make()
 
        update_is_instrument_lib_attr_nolock();
 
+unlock_exit:
        maps_reader_unlock_all();
        maps_writer_unlock();
+
+       return res;
 }
 
 int maps_print_maps_by_addr(const void *addr)
@@ -631,7 +651,11 @@ int maps_is_instrument_section_by_addr(const void *addr)
 
        if (ret == -1) {
                PRINTMSG("========> hz addr %p. remap", addr);
-               maps_make();
+               if (maps_make() != 0) {
+                       PRINTERR("maps make failed\n");
+                       ret = -1;
+                       goto exit;
+               }
                ret = maps_is_instrument_section_by_addr_no_remap(addr);
                if (ret == -1) {
                        print_list();
@@ -643,6 +667,7 @@ int maps_is_instrument_section_by_addr(const void *addr)
                }
        }
 
+exit:
        return ret;
 }
 
index 0edaded11344a2c7beb5a5c9a4ea65530e37dad4..dba51cb10c5fb99fe7d5f1bc6b824227186d4c28 100755 (executable)
@@ -191,6 +191,11 @@ static int createSocket(void)
                                        recvlen = recv(gTraceInfo.socket.daemonSock, data_buf,
                                                       log.length, MSG_WAITALL);
 
+                                       if (recvlen != log.length) {
+                                               PRINTERR("Can not get data from daemon sock\n");
+                                               goto free_data_buf;
+                                       }
+
                                        if (log.type == MSG_CONFIG) {
                                                PRINTMSG("MSG_CONFIG");
                                                _configure(data_buf);
@@ -204,6 +209,7 @@ static int createSocket(void)
                                                PRINTERR("unknown message! %d", log.type);
                                        }
 
+free_data_buf:
                                        if (data_buf != NULL)
                                                free(data_buf);
 
@@ -361,7 +367,10 @@ static void *recvThread(void __unused * data)
                                        }
                                        recvlen = recv(gTraceInfo.socket.daemonSock, data_buf,
                                                log.length, MSG_WAITALL);
-
+                                       if (recvlen != log.length) {
+                                               PRINTERR("Can not recv data from\n");
+                                               goto free_data_buf;
+                                       }
                                }
 
                                if (log.type == MSG_CAPTURE_SCREEN) {
@@ -389,6 +398,7 @@ static void *recvThread(void __unused * data)
                                        PRINTERR("recv unknown message. id = (%d)", log.type);
                                }
 
+free_data_buf:
                                if (data_buf) {
                                        free(data_buf);
                                        data_buf = NULL;
@@ -470,8 +480,10 @@ static int create_recv_thread()
        return err;
 }
 
-void _init_(void)
+int _init_(void)
 {
+       int res = 0;
+
        probeBlockStart();
 
        /* redirect stderr and stdout.*/
@@ -501,9 +513,16 @@ void _init_(void)
                 getpid());
 
        gTraceInfo.init_complete = 1;
-       maps_make();
+       if (maps_make() != 0) {
+               PRINTERR("maps make failed\n");
+               res = -1;
+               goto unlock_exit;
+       }
+
+unlock_exit:
        probeBlockEnd();
 
+       return res;
 }
 
 void __attribute__((constructor)) _init_probe()
index 30db24cc3a149f4c4ac42e17654703383ae7575f..5e153fc3cf0cd86f132af09ecba6869e1ef23293 100644 (file)
@@ -549,7 +549,7 @@ static char __attribute__((used)) *pack_ret(char *to, char ret_type, ...)
 /*     return 0; */
 /* } */
 
-extern void _init_(void);
+extern int _init_(void);
 extern void _uninit_(void);
 
 #endif /* __BIN_PROTO_H__ */
index c6258fd95ebe39c6965dcfad0ab3ed30e81549c6..b1e172ef8448be7a9abb0fec477fc55d5860fff3 100644 (file)
@@ -28,6 +28,6 @@
 
 
 extern int maps_init();
-extern void maps_make();
+extern int maps_make();
 extern int maps_is_instrument_section_by_addr(const void *addr);
 extern int set_map_inst_list(char **maps_set, uint32_t maps_count);
index 2436634bff88ab8bc514adf6b301d138d41152ea..20bce751c77b4a8a044993dc2399971983d50111 100644 (file)
@@ -50,12 +50,15 @@ Eina_Bool _da_onclientmessagereceived(void __unused *pData, int __unused type,
        probeBlockStart();
        pClientEvent = (Ecore_X_Event_Client_Message*)pEvent;
 
-       //This code from ecore_x
-       //So I don't know what 32 does mean
-       if (pClientEvent->format != 32)
-               return ECORE_CALLBACK_PASS_ON;
-
        if (pClientEvent != NULL) {
+
+               //This code from ecore_x
+               //So I don't know what 32 does mean
+               if (pClientEvent->format != 32) {
+                       probeBlockEnd();
+                       return ECORE_CALLBACK_PASS_ON;
+               }
+
                if (pClientEvent->message_type ==
                    ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_PREPARE) {
                        int orientation = (int)pClientEvent->data.l[1];