elm: prevent from accessing null pointer after memory allocation

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
This commit is contained in:
WooHyun Jung 2019-01-29 09:23:44 -05:00 committed by Mike Blumenkrantz
parent c69b340f25
commit 7f2b26861f
12 changed files with 19 additions and 0 deletions

View File

@ -440,6 +440,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;

View 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;

View 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;
@ -998,6 +999,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;

View 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;

View File

@ -5825,6 +5825,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);

View 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

View 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;

View 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;

View 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);

View 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;

View 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);

View 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));