summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2021-04-10 11:23:05 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2021-04-10 13:11:07 +0200
commit1ef48e2f4458d3a52d5f153b9ef11c2dffe96a15 (patch)
treef44f9641b367512dc4fd8d50ecda8ee5d476f5b3 /src
parent0dc949709f23ac9835c3fac67239f8c265e0d041 (diff)
efl_io_model: do not self reference, this is dangerous
what happened here is that people passed private data with a reference to the object. Which is kind of a bad idea, as in some unthought of conditions, events are forgot, which results in freeed memory beeing accessed. This way its at least a error.
Diffstat (limited to 'src')
-rw-r--r--src/lib/eio/efl_io_model.c44
-rw-r--r--src/lib/eio/efl_io_model_private.h2
2 files changed, 25 insertions, 21 deletions
diff --git a/src/lib/eio/efl_io_model.c b/src/lib/eio/efl_io_model.c
index 88c32b19b8..0d5e372eef 100644
--- a/src/lib/eio/efl_io_model.c
+++ b/src/lib/eio/efl_io_model.c
@@ -21,7 +21,7 @@
21#define MY_CLASS_NAME "Efl_Io_Model" 21#define MY_CLASS_NAME "Efl_Io_Model"
22 22
23static void _efl_io_model_info_free(Efl_Io_Model_Info *info, Eina_Bool model); 23static void _efl_io_model_info_free(Efl_Io_Model_Info *info, Eina_Bool model);
24static void _efl_io_model_efl_model_monitor_add(Efl_Io_Model_Data *priv); 24static void _efl_io_model_efl_model_monitor_add(const Eo *obj, Efl_Io_Model_Data *priv);
25 25
26EINA_VALUE_STRUCT_DESC_DEFINE(_eina_file_direct_info_desc, 26EINA_VALUE_STRUCT_DESC_DEFINE(_eina_file_direct_info_desc,
27 NULL, 27 NULL,
@@ -80,14 +80,17 @@ static Eina_Bool
80_efl_model_evt_added_ecore_cb(void *data, int type, void *event) 80_efl_model_evt_added_ecore_cb(void *data, int type, void *event)
81{ 81{
82 Eio_Monitor_Event *ev = event; 82 Eio_Monitor_Event *ev = event;
83 Efl_Io_Model *obj; 83 Efl_Io_Model *obj = data;
84 Efl_Io_Model_Data *pd = data; 84 Efl_Io_Model_Data *pd;
85 Efl_Model_Children_Event cevt; 85 Efl_Model_Children_Event cevt;
86 Efl_Io_Model_Info *mi; 86 Efl_Io_Model_Info *mi;
87 Eina_List *l; 87 Eina_List *l;
88 Eina_Stringshare *spath = NULL; 88 Eina_Stringshare *spath = NULL;
89 char *path = NULL; 89 char *path = NULL;
90 90
91 pd = efl_data_scope_get(obj, EFL_IO_MODEL_CLASS);
92 EINA_SAFETY_ON_NULL_RETURN_VAL(pd, EINA_TRUE);
93
91 if (type != EIO_MONITOR_DIRECTORY_CREATED && type != EIO_MONITOR_FILE_CREATED) 94 if (type != EIO_MONITOR_DIRECTORY_CREATED && type != EIO_MONITOR_FILE_CREATED)
92 return EINA_TRUE; 95 return EINA_TRUE;
93 96
@@ -96,8 +99,6 @@ _efl_model_evt_added_ecore_cb(void *data, int type, void *event)
96 if (_already_added(pd, ev->filename)) 99 if (_already_added(pd, ev->filename))
97 return EINA_TRUE; 100 return EINA_TRUE;
98 101
99 obj = pd->self;
100
101 path = ecore_file_dir_get(ev->filename); 102 path = ecore_file_dir_get(ev->filename);
102 if (!eina_streq(pd->path, path)) 103 if (!eina_streq(pd->path, path))
103 goto end; 104 goto end;
@@ -155,11 +156,10 @@ _efl_model_evt_added_ecore_cb(void *data, int type, void *event)
155} 156}
156 157
157static void 158static void
158_model_child_remove(Efl_Io_Model_Data *pd, Eina_Stringshare *path) 159_model_child_remove(Efl_Io_Model *obj, Efl_Io_Model_Data *pd, Eina_Stringshare *path)
159{ 160{
160 Efl_Io_Model_Info *mi; 161 Efl_Io_Model_Info *mi;
161 Eina_List *l; 162 Eina_List *l;
162 Efl_Io_Model *obj = pd->self;
163 Efl_Model_Children_Event cevt = { 0 }; 163 Efl_Model_Children_Event cevt = { 0 };
164 unsigned int i = 0; 164 unsigned int i = 0;
165 165
@@ -191,16 +191,20 @@ static Eina_Bool
191_efl_model_evt_deleted_ecore_cb(void *data, int type, void *event) 191_efl_model_evt_deleted_ecore_cb(void *data, int type, void *event)
192{ 192{
193 Eio_Monitor_Event *ev = event; 193 Eio_Monitor_Event *ev = event;
194 Efl_Io_Model_Data *pd = data; 194 Efl_Io_Model *obj = data;
195 Efl_Io_Model_Data *pd;
195 Eina_Stringshare *spath = NULL; 196 Eina_Stringshare *spath = NULL;
196 197
198 pd = efl_data_scope_get(obj, EFL_IO_MODEL_CLASS);
199 EINA_SAFETY_ON_FALSE_RETURN_VAL(pd, EINA_TRUE);
200
197 if (type != EIO_MONITOR_DIRECTORY_DELETED && type != EIO_MONITOR_FILE_DELETED) 201 if (type != EIO_MONITOR_DIRECTORY_DELETED && type != EIO_MONITOR_FILE_DELETED)
198 return EINA_TRUE; 202 return EINA_TRUE;
199 203
200 if (ev->monitor != pd->monitor) return EINA_TRUE; 204 if (ev->monitor != pd->monitor) return EINA_TRUE;
201 205
202 spath = eina_stringshare_add(ev->filename); 206 spath = eina_stringshare_add(ev->filename);
203 _model_child_remove(pd, spath); 207 _model_child_remove(obj, pd, spath);
204 eina_stringshare_del(spath); 208 eina_stringshare_del(spath);
205 209
206 return EINA_TRUE; 210 return EINA_TRUE;
@@ -222,13 +226,17 @@ _eio_del_cleanup(Efl_Io_Model *obj)
222static void 226static void
223_eio_done_unlink_cb(void *data, Eio_File *handler EINA_UNUSED) 227_eio_done_unlink_cb(void *data, Eio_File *handler EINA_UNUSED)
224{ 228{
225 Efl_Io_Model *child = data; 229 Efl_Io_Model *child = data, *parent;
226 Efl_Io_Model_Data *child_pd, *pd; 230 Efl_Io_Model_Data *child_pd, *pd;
227 231
232 parent = efl_parent_get(child);
233 EINA_SAFETY_ON_NULL_RETURN(parent);
228 child_pd = efl_data_scope_get(child, MY_CLASS); 234 child_pd = efl_data_scope_get(child, MY_CLASS);
229 pd = efl_data_scope_get(efl_parent_get(child), MY_CLASS); 235 EINA_SAFETY_ON_NULL_RETURN(child_pd);
236 pd = efl_data_scope_get(parent, MY_CLASS);
237 EINA_SAFETY_ON_NULL_RETURN(parent);
230 238
231 _model_child_remove(pd, child_pd->path); 239 _model_child_remove(parent, pd, child_pd->path);
232 _eio_del_cleanup(child); 240 _eio_del_cleanup(child);
233} 241}
234 242
@@ -342,7 +350,7 @@ _eio_build_st_done(void *data, Eio_File *handler EINA_UNUSED, const Eina_Stat *s
342 if (eio_file_is_dir(pd->st)) 350 if (eio_file_is_dir(pd->st))
343 { 351 {
344 // Now that we know we are a directory, we should whatch it 352 // Now that we know we are a directory, we should whatch it
345 _efl_io_model_efl_model_monitor_add(pd); 353 _efl_io_model_efl_model_monitor_add(model, pd);
346 354
347 // And start listing its child 355 // And start listing its child
348 efl_model_children_count_get(model); 356 efl_model_children_count_get(model);
@@ -861,7 +869,7 @@ _efl_io_model_efl_model_children_count_get(const Eo *obj, Efl_Io_Model_Data *pd)
861 869
862 //start monitoring before listing is done 870 //start monitoring before listing is done
863 //we will filter later on if we already published a file or not 871 //we will filter later on if we already published a file or not
864 _efl_io_model_efl_model_monitor_add(pd); 872 _efl_io_model_efl_model_monitor_add(obj, pd);
865 pd->request.listing = efl_future_then(obj, f, 873 pd->request.listing = efl_future_then(obj, f,
866 .free = _efl_io_model_children_list_cleanup, 874 .free = _efl_io_model_children_list_cleanup,
867 .data = pd); 875 .data = pd);
@@ -871,7 +879,7 @@ _efl_io_model_efl_model_children_count_get(const Eo *obj, Efl_Io_Model_Data *pd)
871} 879}
872 880
873static void 881static void
874_efl_io_model_efl_model_monitor_add(Efl_Io_Model_Data *priv) 882_efl_io_model_efl_model_monitor_add(const Eo *obj, Efl_Io_Model_Data *priv)
875{ 883{
876 if (!priv->monitor) 884 if (!priv->monitor)
877 { 885 {
@@ -881,11 +889,11 @@ _efl_io_model_efl_model_monitor_add(Efl_Io_Model_Data *priv)
881 889
882 for (i = 0; priv->mon.mon_event_child_add[i] != EIO_MONITOR_ERROR ; ++i) 890 for (i = 0; priv->mon.mon_event_child_add[i] != EIO_MONITOR_ERROR ; ++i)
883 priv->mon.ecore_child_add_handler[i] = 891 priv->mon.ecore_child_add_handler[i] =
884 ecore_event_handler_add(priv->mon.mon_event_child_add[i], _efl_model_evt_added_ecore_cb, priv); 892 ecore_event_handler_add(priv->mon.mon_event_child_add[i], _efl_model_evt_added_ecore_cb, obj);
885 893
886 for (i = 0; priv->mon.mon_event_child_del[i] != EIO_MONITOR_ERROR ; ++i) 894 for (i = 0; priv->mon.mon_event_child_del[i] != EIO_MONITOR_ERROR ; ++i)
887 priv->mon.ecore_child_del_handler[i] = 895 priv->mon.ecore_child_del_handler[i] =
888 ecore_event_handler_add(priv->mon.mon_event_child_del[i], _efl_model_evt_deleted_ecore_cb, priv); 896 ecore_event_handler_add(priv->mon.mon_event_child_del[i], _efl_model_evt_deleted_ecore_cb, obj);
889 } 897 }
890} 898}
891 899
@@ -1059,8 +1067,6 @@ _efl_io_model_efl_object_finalize(Eo *obj, Efl_Io_Model_Data *pd)
1059 pd->mon.mon_event_child_del[1] = EIO_MONITOR_FILE_DELETED; 1067 pd->mon.mon_event_child_del[1] = EIO_MONITOR_FILE_DELETED;
1060 pd->mon.mon_event_child_del[2] = EIO_MONITOR_ERROR; 1068 pd->mon.mon_event_child_del[2] = EIO_MONITOR_ERROR;
1061 1069
1062 pd->self = obj;
1063
1064 return obj; 1070 return obj;
1065} 1071}
1066 1072
diff --git a/src/lib/eio/efl_io_model_private.h b/src/lib/eio/efl_io_model_private.h
index 2574ade284..9b75190d62 100644
--- a/src/lib/eio/efl_io_model_private.h
+++ b/src/lib/eio/efl_io_model_private.h
@@ -35,8 +35,6 @@ struct _Efl_Io_Model_Info
35 35
36struct _Efl_Io_Model_Data 36struct _Efl_Io_Model_Data
37{ 37{
38 Efl_Io_Model *self;
39
40 Eina_Stringshare *path; 38 Eina_Stringshare *path;
41 39
42 Efl_Io_Model_Info *info; 40 Efl_Io_Model_Info *info;