mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-29 00:54:56 +01:00
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.
This commit is contained in:
parent
65b2ec2a40
commit
747a694f7f
1 changed files with 12 additions and 3 deletions
15
zathura.c
15
zathura.c
|
@ -10,6 +10,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include <poppler/glib/poppler.h>
|
#include <poppler/glib/poppler.h>
|
||||||
#include <cairo.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);
|
static const size_t limit = ~((size_t)0u);
|
||||||
void* tmp = NULL;
|
void* tmp = NULL;
|
||||||
|
|
||||||
|
assert(nmemb != 0);
|
||||||
|
assert(size != 0);
|
||||||
|
|
||||||
/* Check for overflow. */
|
/* Check for overflow. */
|
||||||
if(nmemb > limit / size)
|
if(nmemb > limit / size)
|
||||||
goto failure;
|
goto failure;
|
||||||
|
@ -2988,9 +2992,14 @@ isc_completion(Argument* argument)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rows = safe_realloc((void**)&rows, n_items, sizeof(CompletionRow));
|
if (n_items == 0) {
|
||||||
if(!rows)
|
free(rows);
|
||||||
out_of_memory();
|
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);
|
gtk_box_pack_start(Zathura.UI.box, GTK_WIDGET(results), FALSE, FALSE, 0);
|
||||||
|
|
Loading…
Reference in a new issue