summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-07-28 10:59:15 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-07-28 11:00:35 +0900
commit1c7663e3118e41bf2e96b702a6dff796f35f81db (patch)
tree53be93c9b389275511402646ee74341576340db6
parent7efa27faed12dc57f5f44fb635e26482955ca0cf (diff)
edje entry - check all minor struct callocs and on fail report + unwind
lots of unchecked malloc/calloc returns, so check these, unwind safely and complain (highly unlikely to happen unless the system is about to fall over). this should fix T4230
-rw-r--r--src/lib/edje/edje_entry.c176
1 files changed, 119 insertions, 57 deletions
diff --git a/src/lib/edje/edje_entry.c b/src/lib/edje/edje_entry.c
index cb9f732..85d9e31 100644
--- a/src/lib/edje/edje_entry.c
+++ b/src/lib/edje/edje_entry.c
@@ -249,7 +249,11 @@ _text_filter_markup_prepend_internal(Edje *ed, Entry *en, Evas_Textblock_Cursor
249 if (changeinfo) 249 if (changeinfo)
250 { 250 {
251 info = calloc(1, sizeof(*info)); 251 info = calloc(1, sizeof(*info));
252 if (info) 252 if (!info)
253 {
254 ERR("Running very low on memory");
255 }
256 else
253 { 257 {
254 info->insert = EINA_TRUE; 258 info->insert = EINA_TRUE;
255 info->change.insert.content = eina_stringshare_add(text); 259 info->change.insert.content = eina_stringshare_add(text);
@@ -684,7 +688,7 @@ _sel_update(Edje *ed, Evas_Textblock_Cursor *c EINA_UNUSED, Evas_Object *o, Entr
684 { 688 {
685 Eina_Iterator *range = NULL; 689 Eina_Iterator *range = NULL;
686 Eina_List *l; 690 Eina_List *l;
687 Sel *sel; 691 Sel *sel = NULL;
688 Evas_Textblock_Rectangle *r; 692 Evas_Textblock_Rectangle *r;
689 693
690 range = evas_textblock_cursor_range_simple_geometry_get(en->sel_start, 694 range = evas_textblock_cursor_range_simple_geometry_get(en->sel_start,
@@ -698,6 +702,11 @@ _sel_update(Edje *ed, Evas_Textblock_Cursor *c EINA_UNUSED, Evas_Object *o, Entr
698 Evas_Object *ob; 702 Evas_Object *ob;
699 703
700 sel = calloc(1, sizeof(Sel)); 704 sel = calloc(1, sizeof(Sel));
705 if (!sel)
706 {
707 ERR("Running very low on memory");
708 break;
709 }
701 en->sel = eina_list_append(en->sel, sel); 710 en->sel = eina_list_append(en->sel, sel);
702 if (en->rp->part->source) 711 if (en->rp->part->source)
703 { 712 {
@@ -1015,6 +1024,11 @@ _item_obj_get(Anchor *an, Evas_Object *o, Evas_Object *smart, Evas_Object *clip)
1015 } 1024 }
1016 1025
1017 io = calloc(1, sizeof(Item_Obj)); 1026 io = calloc(1, sizeof(Item_Obj));
1027 if (!io)
1028 {
1029 ERR("Running very low on memory");
1030 return NULL;
1031 }
1018 1032
1019 obj = ed->item_provider.func 1033 obj = ed->item_provider.func
1020 (ed->item_provider.data, smart, 1034 (ed->item_provider.data, smart,
@@ -1078,7 +1092,7 @@ _anchors_update(Evas_Textblock_Cursor *c EINA_UNUSED, Evas_Object *o, Entry *en)
1078 Evas_Coord vx, vy, vw, vh; 1092 Evas_Coord vx, vy, vw, vh;
1079 Evas_Coord tvh, tvw; 1093 Evas_Coord tvh, tvw;
1080 Evas_Object *smart, *clip; 1094 Evas_Object *smart, *clip;
1081 Sel *sel; 1095 Sel *sel = NULL;
1082 Anchor *an; 1096 Anchor *an;
1083 Edje *ed = en->ed; 1097 Edje *ed = en->ed;
1084 1098
@@ -1122,25 +1136,24 @@ _anchors_update(Evas_Textblock_Cursor *c EINA_UNUSED, Evas_Object *o, Entry *en)
1122 Evas_Object *ob; 1136 Evas_Object *ob;
1123 1137
1124 sel = calloc(1, sizeof(Sel)); 1138 sel = calloc(1, sizeof(Sel));
1125 if (sel) 1139 if (!sel)
1126 { 1140 {
1127 an->sel = eina_list_append(an->sel, sel); 1141 ERR("Running very low on memory");
1142 break;
1143 }
1144 an->sel = eina_list_append(an->sel, sel);
1128 1145
1129 if (ed->item_provider.func) 1146 if (ed->item_provider.func)
1130 { 1147 {
1131 ob = _item_obj_get(an, o, smart, clip); 1148 ob = _item_obj_get(an, o, smart, clip);
1132 sel->obj = ob; 1149 sel->obj = ob;
1133 }
1134 } 1150 }
1135 } 1151 }
1136 if (sel) 1152 /* We have only one sel per item */
1137 { 1153 sel = an->sel->data;
1138 /* We have only one sel per item */ 1154 evas_object_move(sel->obj, x + cx, y + cy);
1139 sel = an->sel->data; 1155 evas_object_resize(sel->obj, cw, ch);
1140 evas_object_move(sel->obj, x + cx, y + cy); 1156 evas_object_show(sel->obj);
1141 evas_object_resize(sel->obj, cw, ch);
1142 evas_object_show(sel->obj);
1143 }
1144 } 1157 }
1145 // for link anchors 1158 // for link anchors
1146 else 1159 else
@@ -1189,6 +1202,11 @@ _anchors_update(Evas_Textblock_Cursor *c EINA_UNUSED, Evas_Object *o, Entry *en)
1189 Evas_Object *ob; 1202 Evas_Object *ob;
1190 1203
1191 sel = calloc(1, sizeof(Sel)); 1204 sel = calloc(1, sizeof(Sel));
1205 if (!sel)
1206 {
1207 ERR("Running very low on memory");
1208 break;
1209 }
1192 an->sel = eina_list_append(an->sel, sel); 1210 an->sel = eina_list_append(an->sel, sel);
1193 if (en->rp->part->source5) 1211 if (en->rp->part->source5)
1194 { 1212 {
@@ -1387,6 +1405,11 @@ _anchor_format_parse(const char *item)
1387 else len = strlen(start); 1405 else len = strlen(start);
1388 1406
1389 tmp = malloc(len + 1); 1407 tmp = malloc(len + 1);
1408 if (!tmp)
1409 {
1410 ERR("Running out of memory when allocating %lu byte string", (unsigned long)len + 1);
1411 return NULL;
1412 }
1390 strncpy(tmp, start, len); 1413 strncpy(tmp, start, len);
1391 tmp[len] = '\0'; 1414 tmp[len] = '\0';
1392 1415
@@ -1413,7 +1436,10 @@ _anchors_get(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en)
1413 char *p; 1436 char *p;
1414 an = calloc(1, sizeof(Anchor)); 1437 an = calloc(1, sizeof(Anchor));
1415 if (!an) 1438 if (!an)
1416 break; 1439 {
1440 ERR("Running very low on memory");
1441 break;
1442 }
1417 1443
1418 an->en = en; 1444 an->en = en;
1419 p = strstr(s, "href="); 1445 p = strstr(s, "href=");
@@ -1463,7 +1489,10 @@ _anchors_get(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en)
1463 char *p; 1489 char *p;
1464 an = calloc(1, sizeof(Anchor)); 1490 an = calloc(1, sizeof(Anchor));
1465 if (!an) 1491 if (!an)
1466 break; 1492 {
1493 ERR("Running very low on memory");
1494 break;
1495 }
1467 1496
1468 an->en = en; 1497 an->en = en;
1469 an->item = 1; 1498 an->item = 1;
@@ -1511,6 +1540,11 @@ _range_del_emit(Edje *ed, Evas_Textblock_Cursor *c EINA_UNUSED, Evas_Object *o E
1511 goto noop; 1540 goto noop;
1512 1541
1513 info = calloc(1, sizeof(*info)); 1542 info = calloc(1, sizeof(*info));
1543 if (!info)
1544 {
1545 ERR("Running very low on memory");
1546 goto noop;
1547 }
1514 info->insert = EINA_FALSE; 1548 info->insert = EINA_FALSE;
1515 info->change.del.start = start; 1549 info->change.del.start = start;
1516 info->change.del.end = end; 1550 info->change.del.end = end;
@@ -1544,6 +1578,11 @@ _delete_emit(Edje *ed, Evas_Textblock_Cursor *c, Entry *en, size_t pos,
1544 evas_textblock_cursor_char_prev(c); 1578 evas_textblock_cursor_char_prev(c);
1545 1579
1546 Edje_Entry_Change_Info *info = calloc(1, sizeof(*info)); 1580 Edje_Entry_Change_Info *info = calloc(1, sizeof(*info));
1581 if (!info)
1582 {
1583 ERR("Running very low on memory");
1584 return;
1585 }
1547 char *tmp = evas_textblock_cursor_content_get(c); 1586 char *tmp = evas_textblock_cursor_content_get(c);
1548 1587
1549 info->insert = EINA_FALSE; 1588 info->insert = EINA_FALSE;
@@ -2021,22 +2060,29 @@ _edje_key_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
2021 else 2060 else
2022 { 2061 {
2023 Edje_Entry_Change_Info *info = calloc(1, sizeof(*info)); 2062 Edje_Entry_Change_Info *info = calloc(1, sizeof(*info));
2024 info->insert = EINA_TRUE; 2063 if (!info)
2025 info->change.insert.plain_length = 1;
2026
2027 if (en->have_selection)
2028 { 2064 {
2029 _range_del_emit(ed, en->cursor, rp->object, en); 2065 ERR("Running very low on memory");
2030 info->merge = EINA_TRUE; 2066 }
2067 else
2068 {
2069 info->insert = EINA_TRUE;
2070 info->change.insert.plain_length = 1;
2071
2072 if (en->have_selection)
2073 {
2074 _range_del_emit(ed, en->cursor, rp->object, en);
2075 info->merge = EINA_TRUE;
2076 }
2077 info->change.insert.pos =
2078 evas_textblock_cursor_pos_get(en->cursor);
2079 info->change.insert.content = eina_stringshare_add("<tab/>");
2080 _text_filter_format_prepend(ed, en, en->cursor, "tab");
2081 _anchors_get(en->cursor, rp->object, en);
2082 _edje_emit(ed, "entry,changed", rp->part->name);
2083 _edje_emit_full(ed, "entry,changed,user", rp->part->name,
2084 info, _free_entry_change_info);
2031 } 2085 }
2032 info->change.insert.pos =
2033 evas_textblock_cursor_pos_get(en->cursor);
2034 info->change.insert.content = eina_stringshare_add("<tab/>");
2035 _text_filter_format_prepend(ed, en, en->cursor, "tab");
2036 _anchors_get(en->cursor, rp->object, en);
2037 _edje_emit(ed, "entry,changed", rp->part->name);
2038 _edje_emit_full(ed, "entry,changed,user", rp->part->name,
2039 info, _free_entry_change_info);
2040 } 2086 }
2041 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; 2087 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2042 } 2088 }
@@ -2101,33 +2147,40 @@ _edje_key_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
2101 if (multiline) 2147 if (multiline)
2102 { 2148 {
2103 Edje_Entry_Change_Info *info = calloc(1, sizeof(*info)); 2149 Edje_Entry_Change_Info *info = calloc(1, sizeof(*info));
2104 info->insert = EINA_TRUE; 2150 if (!info)
2105 info->change.insert.plain_length = 1;
2106 if (en->have_selection)
2107 {
2108 _range_del_emit(ed, en->cursor, rp->object, en);
2109 info->merge = EINA_TRUE;
2110 }
2111
2112 info->change.insert.pos =
2113 evas_textblock_cursor_pos_get(en->cursor);
2114 if (shift ||
2115 evas_object_textblock_legacy_newline_get(rp->object))
2116 { 2151 {
2117 _text_filter_format_prepend(ed, en, en->cursor, "br"); 2152 ERR("Running very low on memory");
2118 info->change.insert.content = eina_stringshare_add("<br/>");
2119 } 2153 }
2120 else 2154 else
2121 { 2155 {
2122 _text_filter_format_prepend(ed, en, en->cursor, "ps"); 2156 info->insert = EINA_TRUE;
2123 info->change.insert.content = eina_stringshare_add("<ps/>"); 2157 info->change.insert.plain_length = 1;
2158 if (en->have_selection)
2159 {
2160 _range_del_emit(ed, en->cursor, rp->object, en);
2161 info->merge = EINA_TRUE;
2162 }
2163
2164 info->change.insert.pos =
2165 evas_textblock_cursor_pos_get(en->cursor);
2166 if (shift ||
2167 evas_object_textblock_legacy_newline_get(rp->object))
2168 {
2169 _text_filter_format_prepend(ed, en, en->cursor, "br");
2170 info->change.insert.content = eina_stringshare_add("<br/>");
2171 }
2172 else
2173 {
2174 _text_filter_format_prepend(ed, en, en->cursor, "ps");
2175 info->change.insert.content = eina_stringshare_add("<ps/>");
2176 }
2177 _anchors_get(en->cursor, rp->object, en);
2178 _edje_emit(ed, "entry,changed", rp->part->name);
2179 _edje_emit_full(ed, "entry,changed,user", rp->part->name,
2180 info, _free_entry_change_info);
2181 _edje_emit(ed, "cursor,changed", rp->part->name);
2182 cursor_changed = EINA_TRUE;
2124 } 2183 }
2125 _anchors_get(en->cursor, rp->object, en);
2126 _edje_emit(ed, "entry,changed", rp->part->name);
2127 _edje_emit_full(ed, "entry,changed,user", rp->part->name,
2128 info, _free_entry_change_info);
2129 _edje_emit(ed, "cursor,changed", rp->part->name);
2130 cursor_changed = EINA_TRUE;
2131 } 2184 }
2132 _edje_emit(ed, "entry,key,enter", rp->part->name); 2185 _edje_emit(ed, "entry,key,enter", rp->part->name);
2133 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; 2186 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
@@ -2771,7 +2824,11 @@ _edje_entry_real_part_init(Edje *ed, Edje_Real_Part *rp)
2771 if ((rp->type != EDJE_RP_TYPE_TEXT) || 2824 if ((rp->type != EDJE_RP_TYPE_TEXT) ||
2772 (!rp->typedata.text)) return; 2825 (!rp->typedata.text)) return;
2773 en = calloc(1, sizeof(Entry)); 2826 en = calloc(1, sizeof(Entry));
2774 if (!en) return; 2827 if (!en)
2828 {
2829 ERR("Running very low on memory");
2830 return;
2831 }
2775 rp->typedata.text->entry_data = en; 2832 rp->typedata.text->entry_data = en;
2776 en->rp = rp; 2833 en->rp = rp;
2777 en->ed = ed; 2834 en->ed = ed;
@@ -4644,6 +4701,11 @@ _edje_entry_imf_event_delete_surrounding_cb(void *data, Ecore_IMF_Context *ctx E
4644 _anchors_get(en->cursor, rp->object, en); 4701 _anchors_get(en->cursor, rp->object, en);
4645 _anchors_update_check(ed, rp); 4702 _anchors_update_check(ed, rp);
4646 info = calloc(1, sizeof(*info)); 4703 info = calloc(1, sizeof(*info));
4704 if (!info)
4705 {
4706 ERR("Running very low on memory");
4707 return;
4708 }
4647 info->insert = EINA_FALSE; 4709 info->insert = EINA_FALSE;
4648 info->change.del.start = start; 4710 info->change.del.start = start;
4649 info->change.del.end = end; 4711 info->change.del.end = end;