summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorPankaj Mittal <m.pankaj@samsung.com>2015-12-10 16:26:56 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-12-10 16:26:56 +0900
commit1363cd757a8dcdc9adeaf47f781ad038446b2014 (patch)
tree5cb4b8deb2c4627b57d170269f0fd2bbb244344c /src/lib
parentd63cc52c584e0b3304699bd1822df18c0b446e2b (diff)
evas_eet: Add Type Safety check
Summary: The Function _evas_canvas3d_eet_file_free(void) is referenced in evas_model_load_file_eet()(file:evas_model_load_eet.c at line 122). This call is under condition if ((eet_file->mesh == NULL) || (eet_file->header == NULL)). when either eet_file->mesh or eet_file->header are NULL, dereference of the corresponding pointer in function "_evas_canvas3d_eet_file_free()" will generate Segmentation Fault. @fix Reviewers: raster, Hermet, tasn, wonsik, spacegrapher, cedric, jpeg Subscribers: singh.amitesh, sachin.dev, alok25, yashu21985, mvsovani, cedric Differential Revision: https://phab.enlightenment.org/D3369
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/evas/canvas/evas_canvas3d_eet.c75
-rw-r--r--src/lib/evas/include/evas_common_private.h3
-rw-r--r--src/lib/evas/include/evas_private.h8
3 files changed, 57 insertions, 29 deletions
diff --git a/src/lib/evas/canvas/evas_canvas3d_eet.c b/src/lib/evas/canvas/evas_canvas3d_eet.c
index 281f69da82..aed6512cb2 100644
--- a/src/lib/evas/canvas/evas_canvas3d_eet.c
+++ b/src/lib/evas/canvas/evas_canvas3d_eet.c
@@ -2,18 +2,16 @@
2#include "evas_common_private.h" 2#include "evas_common_private.h"
3#include "evas_private.h" 3#include "evas_private.h"
4 4
5Evas_Canvas3D_File_Eet* eet_file; 5static Eet_Data_Descriptor *_vec2_descriptor = NULL;
6const char EVAS_CANVAS3D_FILE_CACHE_FILE_ENTRY[] = "evas_3d file"; 6static Eet_Data_Descriptor *_vec3_descriptor = NULL;
7Eet_Data_Descriptor *_vec2_descriptor; 7static Eet_Data_Descriptor *_vertex_descriptor = NULL;
8Eet_Data_Descriptor *_vec3_descriptor; 8static Eet_Data_Descriptor *_geometry_descriptor = NULL;
9Eet_Data_Descriptor *_vertex_descriptor; 9static Eet_Data_Descriptor *_color_descriptor = NULL;
10Eet_Data_Descriptor *_geometry_descriptor; 10static Eet_Data_Descriptor *_material_descriptor = NULL;
11Eet_Data_Descriptor *_color_descriptor; 11static Eet_Data_Descriptor *_frame_descriptor = NULL;
12Eet_Data_Descriptor *_material_descriptor; 12static Eet_Data_Descriptor *_mesh_descriptor = NULL;
13Eet_Data_Descriptor *_frame_descriptor; 13static Eet_Data_Descriptor *_header_descriptor = NULL;
14Eet_Data_Descriptor *_mesh_descriptor; 14static Eet_Data_Descriptor *_file_descriptor = NULL;
15Eet_Data_Descriptor *_header_descriptor;
16Eet_Data_Descriptor *_file_descriptor;
17 15
18Evas_Canvas3D_File_Eet * 16Evas_Canvas3D_File_Eet *
19_evas_canvas3d_eet_file_new(void) 17_evas_canvas3d_eet_file_new(void)
@@ -29,8 +27,16 @@ _evas_canvas3d_eet_file_new(void)
29 return creating_file; 27 return creating_file;
30} 28}
31 29
30Eet_Data_Descriptor*
31_evas_canvas3d_eet_file_get()
32{
33 if(_file_descriptor == NULL)
34 _evas_canvas3d_eet_file_init();
35
36 return _file_descriptor;
37}
32void 38void
33_evas_canvas3d_eet_file_init(void) 39_evas_canvas3d_eet_file_init()
34{ 40{
35 eina_init(); 41 eina_init();
36 eet_init(); 42 eet_init();
@@ -153,38 +159,55 @@ _evas_canvas3d_eet_file_init(void)
153 "mesh", mesh, _mesh_descriptor); 159 "mesh", mesh, _mesh_descriptor);
154 EET_DATA_DESCRIPTOR_ADD_SUB(_file_descriptor, Evas_Canvas3D_File_Eet, 160 EET_DATA_DESCRIPTOR_ADD_SUB(_file_descriptor, Evas_Canvas3D_File_Eet,
155 "header", header, _header_descriptor); 161 "header", header, _header_descriptor);
156
157} 162}
158 163
159void 164void
160_evas_canvas3d_eet_descriptor_shutdown(void) 165_evas_canvas3d_eet_descriptor_shutdown()
161{ 166{
162 eet_data_descriptor_free(_geometry_descriptor); 167 eet_data_descriptor_free(_geometry_descriptor);
168 _geometry_descriptor = NULL;
163 eet_data_descriptor_free(_vertex_descriptor); 169 eet_data_descriptor_free(_vertex_descriptor);
170 _vertex_descriptor = NULL;
164 eet_data_descriptor_free(_vec2_descriptor); 171 eet_data_descriptor_free(_vec2_descriptor);
172 _vec2_descriptor = NULL;
165 eet_data_descriptor_free(_vec3_descriptor); 173 eet_data_descriptor_free(_vec3_descriptor);
174 _vec3_descriptor = NULL;
166 eet_data_descriptor_free(_color_descriptor); 175 eet_data_descriptor_free(_color_descriptor);
176 _color_descriptor = NULL;
167 eet_data_descriptor_free(_material_descriptor); 177 eet_data_descriptor_free(_material_descriptor);
178 _material_descriptor = NULL;
168 eet_data_descriptor_free(_frame_descriptor); 179 eet_data_descriptor_free(_frame_descriptor);
180 _frame_descriptor = NULL;
169 eet_data_descriptor_free(_mesh_descriptor); 181 eet_data_descriptor_free(_mesh_descriptor);
182 _mesh_descriptor = NULL;
170 eet_data_descriptor_free(_header_descriptor); 183 eet_data_descriptor_free(_header_descriptor);
184 _header_descriptor = NULL;
171 eet_data_descriptor_free(_file_descriptor); 185 eet_data_descriptor_free(_file_descriptor);
186 _file_descriptor = NULL;
172} 187}
173 188
174void 189void
175_evas_canvas3d_eet_file_free(void) 190_evas_canvas3d_eet_file_free(Evas_Canvas3D_File_Eet* eet_file)
176{ 191{
177 free(eet_file->mesh->geometries[0].vertices); 192 if (eet_file->mesh)
178 free(eet_file->mesh->geometries); 193 {
179 free(eet_file->mesh->frames); 194 free(eet_file->mesh->geometries[0].vertices);
180 free(eet_file->mesh->materials[0].colors); 195 free(eet_file->mesh->geometries);
181 free(eet_file->mesh->materials); 196 free(eet_file->mesh->frames);
182 free(eet_file->mesh); 197 free(eet_file->mesh->materials[0].colors);
183 free(eet_file->header->materials); 198 free(eet_file->mesh->materials);
184 free(eet_file->header->geometries); 199 free(eet_file->mesh);
185 free(eet_file->header); 200 }
186 free(eet_file);
187 201
202 if (eet_file->header)
203 {
204 free(eet_file->header->materials);
205 free(eet_file->header->geometries);
206 free(eet_file->header);
207 }
208
209 free(eet_file);
210 eet_file = NULL;
188 _evas_canvas3d_eet_descriptor_shutdown(); 211 _evas_canvas3d_eet_descriptor_shutdown();
189 eet_shutdown(); 212 eet_shutdown();
190 eina_shutdown(); 213 eina_shutdown();
diff --git a/src/lib/evas/include/evas_common_private.h b/src/lib/evas/include/evas_common_private.h
index f7deaa7f42..cf29f2d345 100644
--- a/src/lib/evas/include/evas_common_private.h
+++ b/src/lib/evas/include/evas_common_private.h
@@ -90,6 +90,9 @@
90#define lround(x) (((x) < 0) ? (long int)ceil((x) - 0.5) : (long int)floor((x) + 0.5)) 90#define lround(x) (((x) < 0) ? (long int)ceil((x) - 0.5) : (long int)floor((x) + 0.5))
91#endif 91#endif
92 92
93/*macro to be used in eet loader/saver*/
94#define EVAS_CANVAS3D_FILE_CACHE_FILE_ENTRY "evas_3d file"
95
93/* macros needed to log message through eina_log */ 96/* macros needed to log message through eina_log */
94extern EAPI int _evas_log_dom_global; 97extern EAPI int _evas_log_dom_global;
95#ifdef _EVAS_DEFAULT_LOG_DOM 98#ifdef _EVAS_DEFAULT_LOG_DOM
diff --git a/src/lib/evas/include/evas_private.h b/src/lib/evas/include/evas_private.h
index 5ef176f3bc..b6f8c89d63 100644
--- a/src/lib/evas/include/evas_private.h
+++ b/src/lib/evas/include/evas_private.h
@@ -1784,9 +1784,11 @@ void evas_canvas3d_scene_data_fini(Evas_Canvas3D_Scene_Public_Data *data);
1784 1784
1785/* Eet saver/loader functions */ 1785/* Eet saver/loader functions */
1786Evas_Canvas3D_File_Eet *_evas_canvas3d_eet_file_new(void); 1786Evas_Canvas3D_File_Eet *_evas_canvas3d_eet_file_new(void);
1787void _evas_canvas3d_eet_file_init(void); 1787Eet_Data_Descriptor* _evas_canvas3d_eet_file_get();
1788void _evas_canvas3d_eet_descriptor_shutdown(void); 1788void _evas_canvas3d_eet_file_init();
1789void _evas_canvas3d_eet_file_free(void); 1789void _evas_canvas3d_eet_descriptor_shutdown();
1790void _evas_canvas3d_eet_file_free(Evas_Canvas3D_File_Eet* eet_file);
1791
1790 1792
1791/* Filters */ 1793/* Filters */
1792void evas_filter_init(void); 1794void evas_filter_init(void);