From: Thiep Ha Date: Thu, 8 Jun 2017 10:22:46 +0000 (+0900) Subject: map: add more checking on input and memory allocation X-Git-Tag: upstream/1.20.0~702 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b1d287bbf2f1b7edd4404db93a9365d33a08835c;p=platform%2Fupstream%2Fefl.git map: add more checking on input and memory allocation More checking on input parameter and memory allocation when set number of map points. Thanks jp. --- diff --git a/src/lib/evas/canvas/efl_gfx_map.c b/src/lib/evas/canvas/efl_gfx_map.c index 8577ebf..60672c7 100644 --- a/src/lib/evas/canvas/efl_gfx_map.c +++ b/src/lib/evas/canvas/efl_gfx_map.c @@ -175,8 +175,7 @@ _efl_gfx_map_efl_object_destructor(Eo *eo_obj, Efl_Gfx_Map_Data *pd) if (pd->cow) { _map_ops_clean(eo_obj, pd); - if (pd->cow->points) - free(pd->cow->points); + free(pd->cow->points); eina_cow_free(gfx_map_cow, (const Eina_Cow_Data **) &pd->cow); } efl_destructor(efl_super(eo_obj, MY_CLASS)); @@ -528,7 +527,7 @@ _efl_gfx_map_map_point_count_set(Eo *eo_obj EINA_UNUSED, Efl_Gfx_Map_Data *pd, i { Gfx_Map *mcow; - if (count % 4 != 0) + if ((count <= 0) || (count % 4 != 0)) { ERR("Map point count (%d) should be multiples of 4", count); return; @@ -536,11 +535,26 @@ _efl_gfx_map_map_point_count_set(Eo *eo_obj EINA_UNUSED, Efl_Gfx_Map_Data *pd, i if (pd->cow->count == count) return; mcow = MAPCOW_BEGIN(pd); - mcow->count = count; if (mcow->points == NULL) - mcow->points = calloc(1, count * sizeof(Gfx_Map_Point)); + { + mcow->points = calloc(1, count * sizeof(Gfx_Map_Point)); + if (mcow->points) + mcow->count = count; + else + ERR("Failed to allocate memory with calloc"); + } else - mcow->points = realloc(mcow->points, count * sizeof(Gfx_Map_Point)); + { + Gfx_Map_Point *ps = realloc(mcow->points, count * sizeof(Gfx_Map_Point)); + if (ps) + { + mcow->points = ps; + mcow->count = count; + memset(mcow->points, 0, count * sizeof(Gfx_Map_Point)); + } + else + ERR("Failed to allocate memory with realloc"); + } MAPCOW_END(mcow, pd); } diff --git a/src/lib/evas/canvas/evas_map.c b/src/lib/evas/canvas/evas_map.c index 8ccd4ec..5dd5fc1 100644 --- a/src/lib/evas/canvas/evas_map.c +++ b/src/lib/evas/canvas/evas_map.c @@ -649,7 +649,7 @@ evas_object_map_get(const Evas_Object *eo_obj) EAPI Evas_Map * evas_map_new(int count) { - if (count % 4 != 0) + if ((count <= 0) || (count % 4 != 0)) { ERR("map point count (%i) should be multiples of 4!", count); return NULL;