* lib/malloca.c: Include idx.h, intprops.h.
(mmalloca): Check for ptrdiff_t overflow. Since this module uses
_GL_USE_STDLIB_ALLOC, it cannot assume GNU malloc semantics.
* modules/malloca (Depends-on): Add idx, intprops.
2021-04-21 Paul Eggert <eggert@cs.ucla.edu>
+ malloca: avoid ptrdiff_t overflow
+ * lib/malloca.c: Include idx.h, intprops.h.
+ (mmalloca): Check for ptrdiff_t overflow. Since this module uses
+ _GL_USE_STDLIB_ALLOC, it cannot assume GNU malloc semantics.
+ * modules/malloca (Depends-on): Add idx, intprops.
+
careadlinkat: avoid ptrdiff_t overflow
* lib/careadlinkat.c: Include idx.h, minmax.h.
(readlink_stk): Avoid ptrdiff_t overflow in object allocation.
/* Specification. */
#include "malloca.h"
+#include "idx.h"
+#include "intprops.h"
#include "verify.h"
/* The speed critical point in this file is freea() applied to an alloca()
#if HAVE_ALLOCA
/* Allocate one more word, used to determine the address to pass to freea(),
and room for the alignment ≡ sa_alignment_max mod 2*sa_alignment_max. */
- size_t nplus = n + sizeof (small_t) + 2 * sa_alignment_max - 1;
-
- if (nplus >= n)
+ int plus = sizeof (small_t) + 2 * sa_alignment_max - 1;
+ idx_t nplus;
+ if (!INT_ADD_WRAPV (n, plus, &nplus) && !xalloc_oversized (nplus, 1))
{
char *mem = (char *) malloc (nplus);
Depends-on:
alloca-opt
+idx
+intprops
stdint
verify
xalloc-oversized