Skip to content

Commit

Permalink
utils: Fix out-of-bounds writes
Browse files Browse the repository at this point in the history
We are adding terminating NUL into res[len]. To avoid the invalid write, let's allocate len + 1.

Fixes: ebassi/graphene#168
  • Loading branch information
jtojnar committed Aug 25, 2019
1 parent 822b5dd commit 1333bc9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/mutest-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ mutest_strndup (const char *str,
if (len >= str_len)
return mutest_strdup (str);

char *res = malloc (len * sizeof (char));
char *res = malloc ((len + 1) * sizeof (char));
if (res == NULL)
mutest_oom_abort ();

Expand Down Expand Up @@ -367,7 +367,7 @@ string_split (const char *str,
indent[indent_len] = '\0';
}

char *res = malloc (sizeof (char) * len);
char *res = malloc (sizeof (char) * (len + 1));
if (mutest_unlikely (res == NULL))
mutest_oom_abort ();

Expand Down

0 comments on commit 1333bc9

Please sign in to comment.