1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-30 22:43:12 +03:00

Handle NULL input to malloc_usable_size [BZ #28506]

Hoist the NULL check for malloc_usable_size into its entry points in
malloc-debug and malloc and assume non-NULL in all callees.  This fixes
BZ #28506

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
This commit is contained in:
Siddhesh Poyarekar
2021-10-29 14:53:55 +05:30
parent 1d56fd3bae
commit 88e316b064
3 changed files with 25 additions and 35 deletions

View File

@ -2,6 +2,7 @@
MALLOC_CHECK_ exported to a positive value.
Copyright (C) 2012-2021 Free Software Foundation, Inc.
Copyright The GNU Toolchain Authors.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -21,29 +22,24 @@
#include <malloc.h>
#include <string.h>
#include <stdio.h>
#include <support/support.h>
#include <support/check.h>
static int
do_test (void)
{
size_t usable_size;
void *p = malloc (7);
if (!p)
{
printf ("memory allocation failed\n");
return 1;
}
TEST_VERIFY_EXIT (p != NULL);
usable_size = malloc_usable_size (p);
if (usable_size != 7)
{
printf ("malloc_usable_size: expected 7 but got %zu\n", usable_size);
return 1;
}
TEST_COMPARE (usable_size, 7);
memset (p, 0, usable_size);
free (p);
TEST_COMPARE (malloc_usable_size (NULL), 0);
return 0;
}
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
#include "support/test-driver.c"