From b487866e75b12e1e86fbe5582c3981308573b01f Mon Sep 17 00:00:00 2001 From: Patryk Kaczmarek Date: Wed, 12 Sep 2012 07:33:36 +0000 Subject: [PATCH] From: Patryk Kaczmarek MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Firstly, I want to say hallo to everyone, it is my first message to that list. I had prepared several patches for eina module. One of them fix problem with you are having highly discussion, checking if function arguments are not NULL. What’s more: - I had proposed patches for eina_tiler and eina_rectangle functions, now below zero values ( distance and coordinstes ) are not acceptable. - Documentation for eina list specified, it should be more clear now and eina stringshare_strlen fixed (NULL had length 0 ). - eina_convert_atofp wrong return value if fp is NULL (EINA_TRUE instead of EINA_FALSE) I had also attached diff to AUTHORS, ChangeLog and NEWS. SVN revision: 76498 --- legacy/eina/AUTHORS | 1 + legacy/eina/ChangeLog | 7 +++++++ legacy/eina/NEWS | 5 +++++ legacy/eina/src/include/eina_list.h | 4 ++-- legacy/eina/src/include/eina_stringshare.h | 2 +- legacy/eina/src/lib/eina_list.c | 2 ++ legacy/eina/src/lib/eina_quadtree.c | 2 ++ legacy/eina/src/lib/eina_rectangle.c | 3 +++ legacy/eina/src/lib/eina_str.c | 3 +++ legacy/eina/src/lib/eina_tiler.c | 11 +++++++++++ 10 files changed, 37 insertions(+), 3 deletions(-) diff --git a/legacy/eina/AUTHORS b/legacy/eina/AUTHORS index ef0d3cc304..7ee2d6c3e6 100644 --- a/legacy/eina/AUTHORS +++ b/legacy/eina/AUTHORS @@ -25,3 +25,4 @@ Jonas M. Gastal Raphael Kubo da Costa Jérôme Pinot Mike Blumenkrantz +Patryk Kaczmarek diff --git a/legacy/eina/ChangeLog b/legacy/eina/ChangeLog index 403c9d7df7..6b9f822daf 100644 --- a/legacy/eina/ChangeLog +++ b/legacy/eina/ChangeLog @@ -341,3 +341,10 @@ 2012-09-11 Cedric Bail * Speedup Eina Rbtree Iterator by recycling memory instead of massively calling malloc/free. + +2012-09-12 Patryk Kaczmarek + + * Add EINA_SAFETY checks for proper function arguments. + * Add check if given arguments (distance and coordinates) in eina_tiler + and eina_rectangle are not below zero + * Documentation for eina list specified and eina stringshare fixed diff --git a/legacy/eina/NEWS b/legacy/eina/NEWS index c6b08c9ff7..21665d77f8 100644 --- a/legacy/eina/NEWS +++ b/legacy/eina/NEWS @@ -15,6 +15,9 @@ Additions: * Add backtrace support to Eina_Log, use EINA_LOG_BACKTRACE to enable it. * Add an helper to iterate over line in a mapped file. * Add EINA_SENTINEL to protect variadic functions + * Add EINA_SAFETY checks for proper function arguments. + * Add check if given arguments (distance and coordinates) in eina_tiler + and eina_rectangle are not below zero Fixes: * Add missing files in the tarball. @@ -27,6 +30,8 @@ Fixes: * Implement eina_file_map_lines() on Windows. * Handle NULL in all eina_*_free function. * eina_log_console_color_set() + * Documentation for eina list specified and eina stringshare fixed. + * eina_convert_atofp wrong return value if fp is NULL. Removal: * configure options: --disable-posix-threads, --disable-win32-threads, diff --git a/legacy/eina/src/include/eina_list.h b/legacy/eina/src/include/eina_list.h index a0540c8f61..a81f57b801 100644 --- a/legacy/eina/src/include/eina_list.h +++ b/legacy/eina/src/include/eina_list.h @@ -954,8 +954,8 @@ EAPI Eina_List *eina_list_merge(Eina_List *left, Eina_List *right) EI * smallest one to be head of the returned list. It will continue this process * for all entry of both list. * - * Both left and right do not exist anymore after the merge. - * If @p func is @c NULL, it will return @c NULL. + * Both left and right lists are not vailid anymore after the merge and should + * not be used. If @p func is @c NULL, it will return @c NULL. * * Example: * @code diff --git a/legacy/eina/src/include/eina_stringshare.h b/legacy/eina/src/include/eina_stringshare.h index 9a05bcd7e0..21daeaf268 100644 --- a/legacy/eina/src/include/eina_stringshare.h +++ b/legacy/eina/src/include/eina_stringshare.h @@ -311,7 +311,7 @@ EAPI void eina_stringshare_del(Eina_Stringshare *str); * @brief Note that the given string @b must be shared. * * @param str the shared string to know the length. It is safe to - * give @c NULL, in that case @c -1 is returned. + * give @c NULL, in that case @c 0 is returned. * @return The length of a shared string. * * This function is a cheap way to known the length of a shared diff --git a/legacy/eina/src/lib/eina_list.c b/legacy/eina/src/lib/eina_list.c index ea5dfb9433..7ef219def9 100644 --- a/legacy/eina/src/lib/eina_list.c +++ b/legacy/eina/src/lib/eina_list.c @@ -1466,6 +1466,8 @@ eina_list_accessor_new(const Eina_List *list) { Eina_Accessor_List *ac; + EINA_SAFETY_ON_NULL_RETURN_VAL(list, NULL); + eina_error_set(0); ac = calloc(1, sizeof (Eina_Accessor_List)); if (!ac) diff --git a/legacy/eina/src/lib/eina_quadtree.c b/legacy/eina/src/lib/eina_quadtree.c index f0a2dd466c..e163e6fe7a 100644 --- a/legacy/eina/src/lib/eina_quadtree.c +++ b/legacy/eina/src/lib/eina_quadtree.c @@ -875,6 +875,8 @@ eina_quadtree_increase(Eina_QuadTree_Item *object) { size_t tmp; + EINA_MAGIC_CHECK_QUADTREE_ITEM(object); + tmp = object->quad->index++; if (object->index == tmp) return; diff --git a/legacy/eina/src/lib/eina_rectangle.c b/legacy/eina/src/lib/eina_rectangle.c index cfa5ac295c..85cf310c2a 100644 --- a/legacy/eina/src/lib/eina_rectangle.c +++ b/legacy/eina/src/lib/eina_rectangle.c @@ -361,6 +361,9 @@ eina_rectangle_pool_new(int w, int h) { Eina_Rectangle_Pool *new; + if ((w <= 0) || (h <= 0)) + return NULL; + new = malloc(sizeof (Eina_Rectangle_Pool)); if (!new) return NULL; diff --git a/legacy/eina/src/lib/eina_str.c b/legacy/eina/src/lib/eina_str.c index 2a54c00c78..9a1a369c3f 100644 --- a/legacy/eina/src/lib/eina_str.c +++ b/legacy/eina/src/lib/eina_str.c @@ -544,6 +544,9 @@ eina_str_escape(const char *str) char *s2, *d; const char *s; + if (!str) + return NULL; + s2 = malloc((strlen(str) * 2) + 1); if (!s2) return NULL; diff --git a/legacy/eina/src/lib/eina_tiler.c b/legacy/eina/src/lib/eina_tiler.c index 155b0e0037..b436ba6583 100644 --- a/legacy/eina/src/lib/eina_tiler.c +++ b/legacy/eina/src/lib/eina_tiler.c @@ -1115,6 +1115,9 @@ EAPI Eina_Tiler *eina_tiler_new(int w, int h) { Eina_Tiler *t; + if ((w <= 0) || (h <= 0)) + return NULL; + t = calloc(1, sizeof(Eina_Tiler)); t->area.w = w; t->area.h = h; @@ -1151,6 +1154,8 @@ EAPI Eina_Bool eina_tiler_rect_add(Eina_Tiler *t, const Eina_Rectangle *r) Eina_Rectangle tmp; EINA_MAGIC_CHECK_TILER(t, EINA_FALSE); + EINA_SAFETY_ON_NULL_RETURN_VAL(r, EINA_FALSE); + if ((r->w <= 0) || (r->h <= 0)) return EINA_FALSE; @@ -1169,6 +1174,8 @@ EAPI void eina_tiler_rect_del(Eina_Tiler *t, const Eina_Rectangle *r) Eina_Rectangle tmp; EINA_MAGIC_CHECK_TILER(t); + EINA_SAFETY_ON_NULL_RETURN(r); + if ((r->w <= 0) || (r->h <= 0)) return; @@ -1260,6 +1267,10 @@ eina_tile_grid_slicer_iterator_new(int x, { Eina_Tile_Grid_Slicer_Iterator *it; + if ((x < 0) || (y < 0) || (w <= 0) || (h <= 0) || + (tile_w <= 0) || (tile_h <= 0)) + return NULL; + it = calloc(1, sizeof(*it)); if (!it) {