Commit f3b3e543 by Patrick Steinhardt

xdiff: catch memory allocation errors

The xdiff code contains multiple call sites where the results of
`xdl_malloc` are not being checked for memory allocation errors.

Add checks to fix possible segfaults due to `NULL` pointer accesses.
parent c2dd895a
......@@ -717,10 +717,22 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
status = 0;
if (!xscr1) {
result->ptr = xdl_malloc(mf2->size);
if (!result->ptr) {
xdl_free_script(xscr2);
xdl_free_env(&xe1);
xdl_free_env(&xe2);
return -1;
}
memcpy(result->ptr, mf2->ptr, mf2->size);
result->size = mf2->size;
} else if (!xscr2) {
result->ptr = xdl_malloc(mf1->size);
if (!result->ptr) {
xdl_free_script(xscr1);
xdl_free_env(&xe1);
xdl_free_env(&xe2);
return -1;
}
memcpy(result->ptr, mf1->ptr, mf1->size);
result->size = mf1->size;
} else {
......
......@@ -217,6 +217,9 @@ static struct entry *find_longest_common_sequence(struct hashmap *map)
*/
int anchor_i = -1;
if (!sequence)
return NULL;
for (entry = map->first; entry; entry = entry->next) {
if (!entry->line2 || entry->line2 == NON_UNIQUE)
continue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment