raster pushed a commit to branch master.

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

commit cdbd437c5f7900a7ce9e4e60e522c1a41150b70b
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Sat Jul 9 12:28:05 2016 +0900

    evas sw generic - handle alloc failures correctly for map struct
    
    map struct allocation was not handled right - we assumed successthen
    later checked for failure with an if() after using the ptr. this
    should fix CID 1353722
---
 .../evas/engines/software_generic/evas_engine.c    | 30 +++++++++++++---------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/modules/evas/engines/software_generic/evas_engine.c 
b/src/modules/evas/engines/software_generic/evas_engine.c
index 4259ba1..50eb313 100644
--- a/src/modules/evas/engines/software_generic/evas_engine.c
+++ b/src/modules/evas/engines/software_generic/evas_engine.c
@@ -1577,6 +1577,11 @@ eng_image_data_map(void *engdata EINA_UNUSED, void 
**image,
           }
 
         map = calloc(1, sizeof(*map));
+        if (!map)
+          {
+             free(data);
+             return NULL;
+          }
         map->allocated = EINA_TRUE;
         map->cspace = cspace;
         map->rx = rx;
@@ -1597,6 +1602,8 @@ eng_image_data_map(void *engdata EINA_UNUSED, void 
**image,
              // no copy
              int end_offset = _evas_common_rgba_image_data_offset(x + w, y + 
h, 0, 0, 0, im) - src_stride;
              map = calloc(1, sizeof(*map));
+             if (!map) return NULL;
+
              map->baseptr = im->image.data8;
              map->ptr = im->image.data8 + src_offset;
              map->size = end_offset - src_offset;
@@ -1607,10 +1614,14 @@ eng_image_data_map(void *engdata EINA_UNUSED, void 
**image,
              int size = _evas_common_rgba_image_data_offset(w, h, 0, 0, 0, im);
              data = malloc(size);
              if (!data) return NULL;
-
+             map = calloc(1, sizeof(*map));
+             if (!map)
+               {
+                  free(data);
+                  return NULL;
+               }
              memcpy(data, im->image.data8 + src_offset, size);
 
-             map = calloc(1, sizeof(*map));
              map->allocated = EINA_TRUE;
              map->baseptr = data;
              map->ptr = data;
@@ -1624,16 +1635,11 @@ eng_image_data_map(void *engdata EINA_UNUSED, void 
**image,
         map->stride = src_stride;
      }
 
-   if (map)
-     {
-        im->maps = (RGBA_Image_Data_Map *)
-              eina_inlist_prepend(EINA_INLIST_GET(im->maps), 
EINA_INLIST_GET(map));
-        if (length) *length = map->size;
-        if (stride) *stride = map->stride;
-        return map->ptr;
-     }
-
-   return NULL;
+   im->maps = (RGBA_Image_Data_Map *)
+     eina_inlist_prepend(EINA_INLIST_GET(im->maps), EINA_INLIST_GET(map));
+   if (length) *length = map->size;
+   if (stride) *stride = map->stride;
+   return map->ptr;
 }
 
 static void

-- 


Reply via email to