Skip to content

Commit

Permalink
util: abort for a negative zalloc() size
Browse files Browse the repository at this point in the history
Nothing in libinput needs large buffers, so if we ever get something that
large, we probably passed a negative number to zalloc.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed Jun 11, 2018
1 parent 24a19dd commit 8865d4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/libinput-util.h
Expand Up @@ -141,6 +141,9 @@ zalloc(size_t size)
{
void *p;

if ((ssize_t)size < 0)
abort();

p = calloc(1, size);
if (!p)
abort();
Expand Down
10 changes: 10 additions & 0 deletions test/litest-selftest.c
Expand Up @@ -344,6 +344,12 @@ START_TEST(ck_double_ge_fails)
}
END_TEST

START_TEST(zalloc_overflow)
{
zalloc(-1);
}
END_TEST

static Suite *
litest_assert_macros_suite(void)
{
Expand Down Expand Up @@ -408,6 +414,10 @@ litest_assert_macros_suite(void)
tcase_add_exit_test(tc, ck_double_ge_fails, 1);
suite_add_tcase(s, tc);

tc = tcase_create("zalloc ");
tcase_add_test_raise_signal(tc, zalloc_overflow, SIGABRT);
suite_add_tcase(s, tc);

return s;
}

Expand Down

0 comments on commit 8865d4a

Please sign in to comment.