elm: prevent from accessing null pointer after memory allocation
authorWooHyun Jung <wh0705.jung@samsung.com>
Tue, 29 Jan 2019 14:23:44 +0000 (09:23 -0500)
committerTaehyub Kim <taehyub.kim@samsung.com>
Thu, 31 Jan 2019 02:19:59 +0000 (11:19 +0900)
Summary: Add null checking code just after allocating memory

Test Plan: make check

Reviewers: jypark, Jaehyun_Cho, zmike

Reviewed By: Jaehyun_Cho, zmike

Subscribers: devilhorns, zmike, cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D7801

12 files changed:
src/lib/elementary/efl_access_object.c
src/lib/elementary/efl_page_transition_scroll.c
src/lib/elementary/efl_ui_progressbar.c
src/lib/elementary/efl_ui_table.c
src/lib/elementary/efl_ui_widget.c
src/lib/elementary/elm_code.c
src/lib/elementary/elm_code_file.c
src/lib/elementary/elm_code_line.c
src/lib/elementary/elm_code_widget.c
src/lib/elementary/elm_code_widget_text.c
src/lib/elementary/elm_code_widget_undo.c
src/lib/elementary/elm_theme.c

index 137a1b6..acd16c0 100644 (file)
@@ -570,6 +570,7 @@ EOLIAN Efl_Access_Event_Handler *
 _efl_access_object_event_handler_add(Eo *class EINA_UNUSED, void *pd EINA_UNUSED, Efl_Event_Cb cb, void *data)
 {
    Efl_Access_Event_Handler *ret = calloc(1, sizeof(Efl_Access_Event_Handler));
+   if (!ret) return NULL;
 
    ret->cb = cb;
    ret->data = data;
index fa485f1..169bce6 100644 (file)
@@ -41,6 +41,7 @@ _page_info_allocate(Efl_Page_Transition_Scroll_Data *pd,
    for (i = 0; i < pd->page_info_num; i++)
      {
         pi = calloc(1, sizeof(*pi));
+        if (!pi) return;
         if (i == 0) pd->head = pi;
         else if (i == (pd->page_info_num - 1)) pd->tail = pi;
         pi->id = i;
@@ -462,6 +463,7 @@ _add_item(Efl_Page_Transition_Scroll_Data *pd, Efl_Page_Transition_Data *spd)
    Page_Info *pi;
 
    pi = calloc(1, sizeof(*pi));
+   if (!pi) return NULL;
    pi->obj = efl_add(EFL_UI_BOX_CLASS, spd->pager.obj);
    efl_canvas_group_member_add(spd->pager.group, pi->obj);
    pi->content_num = -1;
index 65e912c..319be2a 100644 (file)
@@ -48,6 +48,7 @@ _progress_status_new(const char *part_name, double val)
 {
    Efl_Ui_Progress_Status *ps;
    ps = calloc(1, sizeof(Efl_Ui_Progress_Status));
+   if (!ps) return NULL;
    ps->part_name = eina_stringshare_add(part_name);
    ps->val = val;
    return ps;
@@ -1051,6 +1052,7 @@ elm_progressbar_unit_format_function_set(Evas_Object *obj, progressbar_func_type
 {
    EFL_UI_PROGRESSBAR_DATA_GET_OR_RETURN(obj, sd);
    Pb_Format_Wrapper_Data *pfwd = malloc(sizeof(Pb_Format_Wrapper_Data));
+   if (!pfwd) return;
 
    pfwd->format_cb = func;
    pfwd->format_free_cb = free_func;
index 5e7ccbd..3e5a14d 100644 (file)
@@ -291,6 +291,7 @@ _pack_at(Eo *obj, Efl_Ui_Table_Data *pd, Efl_Gfx_Entity *subobj,
    if (!gi)
      {
         gi = calloc(1, sizeof(*gi));
+        if (!gi) return EINA_FALSE;
         gi->col = col;
         gi->row = row;
         gi->col_span = colspan;
index bc9736e..3409dfb 100644 (file)
@@ -8093,6 +8093,7 @@ _widget_shadow_part_get(const Eo *part_obj)
    if (!shadow)
      {
         shadow = calloc(1, sizeof(*shadow));
+        if (!shadow) return NULL;
         shadow->widget = pd->obj;
         efl_key_data_set(widget, "__elm_shadow", shadow);
         efl_event_callback_array_add(widget, widget_shadow_cb(), shadow);
index cfe1f7e..12c1e4e 100644 (file)
@@ -21,6 +21,7 @@ elm_code_create(void)
    Elm_Code *ret;
 
    ret = calloc(1, sizeof(Elm_Code));
+   if (!ret) return NULL;
    ret->config.indent_style_efl = EINA_TRUE;
 
    // create an in-memory backing for this elm_code by default
index edd0161..1ca3e00 100644 (file)
@@ -97,6 +97,7 @@ EAPI char *_elm_code_file_tmp_path_get(Elm_Code_File *file)
    dirlen = strlen(path) - strlen(name);
 
    tmp = malloc(sizeof(char) * (strlen(path) + 6));
+   if (!tmp) return NULL;
    snprintf(tmp, dirlen + 1, "%s", path);
    snprintf(tmp + dirlen, strlen(name) + 6, ".%s.tmp", name);
 
@@ -111,6 +112,7 @@ EAPI Elm_Code_File *elm_code_file_new(Elm_Code *code)
      elm_code_file_free(code->file);
 
    ret = calloc(1, sizeof(Elm_Code_File));
+   if (!ret) return NULL;
    code->file = ret;
    ret->parent = code;
 
index fd222a3..3c74a47 100644 (file)
@@ -98,6 +98,7 @@ _elm_code_line_merge_into(Elm_Code_Line *line1, Elm_Code_Line *line2)
    text2 = elm_code_line_text_get(line2, &length2);
 
    newtext = malloc(sizeof(char) * (length1 + length2 + 1));
+   if (!newtext) return;
    if (length1 > 0)
      snprintf(newtext, length1 + 1, "%s", text1);
    if (length2 > 0)
@@ -178,6 +179,7 @@ EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int l
      return;
 
    tok = calloc(1, sizeof(Elm_Code_Token));
+   if (!tok) return;
 
    tok->start = start;
    tok->end = end;
index 2656247..3cb4167 100644 (file)
@@ -258,6 +258,7 @@ _elm_code_widget_fill_line_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c
         if (line->number > 0)
           {
              number = malloc(sizeof(char) * gutter);
+             if (!number) return;
              snprintf(number, gutter, "%*d", gutter - 1, line->number);
           }
         for (g = 0; g < gutter - 1; g++)
@@ -1430,6 +1431,7 @@ _elm_code_widget_change_create(unsigned int start_col, unsigned int start_line,
    Elm_Code_Widget_Change_Info *info;
 
    info = calloc(1, sizeof(*info));
+   if (!info) return NULL;
    info->insert = insert;
 
    info->start_col = start_col;
@@ -1540,6 +1542,7 @@ _elm_code_widget_newline(Elm_Code_Widget *widget)
 
    textlen = strlen(leading) + 2;
    text = malloc(sizeof(char) * textlen);
+   if (!text) return;
    snprintf(text, textlen, "\n%s", leading);
    free(leading);
 
index ce1db18..f822339 100644 (file)
@@ -67,6 +67,7 @@ _elm_code_widget_text_multi_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *p
      }
 
    ret = malloc(sizeof(char) * (ret_len + 1));
+   if (!ret) goto end;
 
    snprintf(ret, strlen(first) + newline_len + 1, "%s%s", first, newline);
 
@@ -84,6 +85,7 @@ _elm_code_widget_text_multi_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *p
      }
    snprintf(ptr, strlen(last) + 1, "%s", last);
 
+end:
    free(first);
    free(last);
    return ret;
index 7e983d0..65dbf05 100644 (file)
@@ -31,6 +31,7 @@ _elm_code_widget_undo_info_copy(Elm_Code_Widget_Change_Info *info)
    Elm_Code_Widget_Change_Info *copy;
 
    copy = calloc(1, sizeof(*info));
+   if (!copy) return NULL;
    memcpy(copy, info, sizeof(*info));
    copy->content = strndup(info->content, info->length);
 
index 699ba3a..9c57c93 100644 (file)
@@ -543,6 +543,7 @@ elm_theme_files_copy(Eina_Inlist **dst, Eina_Inlist **src)
    EINA_INLIST_FOREACH(*src, etf)
      {
         cpy = malloc(sizeof(Elm_Theme_File));
+        EINA_SAFETY_ON_NULL_RETURN(cpy);
         cpy->item = eina_stringshare_ref(etf->item);
         cpy->handle = eina_file_dup(etf->handle);
         *dst = eina_inlist_append(*dst, EINA_INLIST_GET(cpy));