From 3491137bdb49791ad2e4c88ccd1367db706658dd Mon Sep 17 00:00:00 2001 From: Michal Jagiello Date: Wed, 10 Oct 2012 09:31:25 +0000 Subject: [PATCH] From: Michal Jagiello Subject: [E-devel] [PATCH][ETHUMB] Null checks and checks if divisor is not equal to zero in ethumb.c file In functions ethumb_calculate_aspect_from_ratio, ethumb_calculate_fill_from_ratio, ethumb_plugin_image_resize and ethumb_image_save Ethumb object is not checked if is NULL, what can cause segmentation fault. In functions ethumb_calculate_aspect and ethumb_calculate_fill divisor is not checked if is equal to zero before division. SVN revision: 77736 --- legacy/ethumb/src/lib/ethumb.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/legacy/ethumb/src/lib/ethumb.c b/legacy/ethumb/src/lib/ethumb.c index ec7f44c828..c76383f804 100644 --- a/legacy/ethumb/src/lib/ethumb.c +++ b/legacy/ethumb/src/lib/ethumb.c @@ -1093,6 +1093,8 @@ ethumb_calculate_aspect_from_ratio(Ethumb *e, float ia, int *w, int *h) { float a; + EINA_SAFETY_ON_NULL_RETURN(e); + *w = e->tw; *h = e->th; @@ -1115,6 +1117,9 @@ ethumb_calculate_aspect(Ethumb *e, int iw, int ih, int *w, int *h) { float ia; + if (ih == 0) + return; + ia = iw / (float)ih; ethumb_calculate_aspect_from_ratio(e, ia, w, h); @@ -1125,6 +1130,8 @@ ethumb_calculate_fill_from_ratio(Ethumb *e, float ia, int *fx, int *fy, int *fw, { float a; + EINA_SAFETY_ON_NULL_RETURN(e); + *fw = e->tw; *fh = e->th; *fx = 0; @@ -1158,6 +1165,10 @@ EAPI void ethumb_calculate_fill(Ethumb *e, int iw, int ih, int *fx, int *fy, int *fw, int *fh) { float ia; + + if (ih == 0) + return; + ia = iw / (float)ih; ethumb_calculate_fill_from_ratio(e, ia, fx, fy, fw, fh); @@ -1204,6 +1215,8 @@ ethumb_plugin_image_resize(Ethumb *e, int w, int h) { Evas_Object *img; + EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0); + img = e->img; if (e->frame) @@ -1236,6 +1249,8 @@ ethumb_image_save(Ethumb *e) char *dname; char flags[256]; + EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0); + evas_damage_rectangle_add(e->sub_e, 0, 0, e->rw, e->rh); evas_render(e->sub_e);