mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-11 04:42:16 +01:00
grep: don't rely on implementation-defined malloc(0) behavior
The very few places that rely on malloc/calloc of a zero-size region won't attempt to dereference it, so just return NULL rather than rolling the dice with the underlying malloc implementation. Reported by: brooks, Shawn Webb
This commit is contained in:
parent
13a9745746
commit
e116e040f3
@ -650,6 +650,8 @@ grep_malloc(size_t size)
|
|||||||
{
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
||||||
|
if (size == 0)
|
||||||
|
return (NULL);
|
||||||
if ((ptr = malloc(size)) == NULL)
|
if ((ptr = malloc(size)) == NULL)
|
||||||
err(2, "malloc");
|
err(2, "malloc");
|
||||||
return (ptr);
|
return (ptr);
|
||||||
@ -663,6 +665,8 @@ grep_calloc(size_t nmemb, size_t size)
|
|||||||
{
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
||||||
|
if (nmemb == 0 || size == 0)
|
||||||
|
return (NULL);
|
||||||
if ((ptr = calloc(nmemb, size)) == NULL)
|
if ((ptr = calloc(nmemb, size)) == NULL)
|
||||||
err(2, "calloc");
|
err(2, "calloc");
|
||||||
return (ptr);
|
return (ptr);
|
||||||
|
Loading…
Reference in New Issue
Block a user