Commit 747a694f authored by Sebastian Ramacher's avatar Sebastian Ramacher
Browse files

Fix problems with nmemb = 0 in safe_realloc (Closes: #80)

We need to handle this one case. It's not safe to use safe_realloc with size or
nmemb = 0.
parent 65b2ec2a
......@@ -10,6 +10,7 @@
#include <unistd.h>
#include <libgen.h>
#include <math.h>
#include <assert.h>
#include <poppler/glib/poppler.h>
#include <cairo.h>
......@@ -1546,6 +1547,9 @@ safe_realloc(void** ptr, size_t nmemb, size_t size)
static const size_t limit = ~((size_t)0u);
void* tmp = NULL;
assert(nmemb != 0);
assert(size != 0);
/* Check for overflow. */
if(nmemb > limit / size)
goto failure;
......@@ -2988,9 +2992,14 @@ isc_completion(Argument* argument)
}
}
rows = safe_realloc((void**)&rows, n_items, sizeof(CompletionRow));
if(!rows)
out_of_memory();
if (n_items == 0) {
free(rows);
rows = NULL;
} else {
rows = safe_realloc((void**)&rows, n_items, sizeof(CompletionRow));
if(!rows)
out_of_memory();
}
}
gtk_box_pack_start(Zathura.UI.box, GTK_WIDGET(results), FALSE, FALSE, 0);
......
Supports Markdown
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