thiep pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=b1d287bbf2f1b7edd4404db93a9365d33a08835c

commit b1d287bbf2f1b7edd4404db93a9365d33a08835c
Author: Thiep Ha <thie...@gmail.com>
Date:   Thu Jun 8 19:22:46 2017 +0900

    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.
---
 src/lib/evas/canvas/efl_gfx_map.c | 26 ++++++++++++++++++++------
 src/lib/evas/canvas/evas_map.c    |  2 +-
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/lib/evas/canvas/efl_gfx_map.c 
b/src/lib/evas/canvas/efl_gfx_map.c
index 8577ebfbf3..60672c7224 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 8ccd4ec418..5dd5fc1d29 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;

-- 


Reply via email to