+2017-08-30 Florian Weimer <fweimer@redhat.com>
+
+ * malloc/dynarray_emplace_enlarge.c
+ (__libc_dynarray_emplace_enlarge): Set errno on overflow.
+ * malloc/dynarray_resize.c (__libc_dynarray_resize): Likewise.
+ * malloc/tst-dynarray.c (test_long_overflow): New function.
+ (do_test): Call it.
+
2017-08-30 Florian Weimer <fweimer@redhat.com>
* malloc/malloc.c (ARENA_CORRUPTION_BIT, arena_is_corrupt)
<http://www.gnu.org/licenses/>. */
#include <dynarray.h>
+#include <errno.h>
#include <malloc-internal.h>
#include <stdlib.h>
#include <string.h>
{
new_allocated = list->allocated + list->allocated / 2 + 1;
if (new_allocated <= list->allocated)
- /* Overflow. */
- return false;
+ {
+ /* Overflow. */
+ __set_errno (ENOMEM);
+ return false;
+ }
}
size_t new_size;
<http://www.gnu.org/licenses/>. */
#include <dynarray.h>
+#include <errno.h>
#include <malloc-internal.h>
#include <stdlib.h>
#include <string.h>
size_t new_size_bytes;
if (check_mul_overflow_size_t (size, element_size, &new_size_bytes))
- return false;
+ {
+ /* Overflow. */
+ __set_errno (ENOMEM);
+ return false;
+ }
void *new_array;
if (list->array == scratch)
{
#include "tst-dynarray-shared.h"
+#include <errno.h>
+#include <stdint.h>
+
#define DYNARRAY_STRUCT dynarray_long
#define DYNARRAY_ELEMENT long
#define DYNARRAY_PREFIX dynarray_long_
}
}
+/* Test overflow in resize. */
+static void
+test_long_overflow (void)
+{
+ {
+ struct dynarray_long dyn;
+ dynarray_long_init (&dyn);
+ errno = EINVAL;
+ TEST_VERIFY (!dynarray_long_resize
+ (&dyn, (SIZE_MAX / sizeof (long)) + 1));
+ TEST_VERIFY (errno == ENOMEM);
+ TEST_VERIFY (dynarray_long_has_failed (&dyn));
+ }
+
+ {
+ struct dynarray_long_noscratch dyn;
+ dynarray_long_noscratch_init (&dyn);
+ errno = EINVAL;
+ TEST_VERIFY (!dynarray_long_noscratch_resize
+ (&dyn, (SIZE_MAX / sizeof (long)) + 1));
+ TEST_VERIFY (errno == ENOMEM);
+ TEST_VERIFY (dynarray_long_noscratch_has_failed (&dyn));
+ }
+}
+
/* Test NUL-terminated string construction with the add function and
the simple finalize function. */
static void
test_int ();
test_str ();
test_long_init ();
+ test_long_overflow ();
test_zstr ();
return 0;
}