X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=lib%2Fxalloc.h;fp=lib%2Fxalloc.h;h=2a51b840db8e6754815d8fbb52f58cb38c167f20;hb=a8a88eddaa90432e6ec1b8d9d5c9842bc91afd1d;hp=a4fddbfb5bb198f5c5ecaa4207904fd3a6cf8031;hpb=20fcfc81ece044b8b0a6768ec6cf47be4e22a2e6;p=debian%2Fgzip
diff --git a/lib/xalloc.h b/lib/xalloc.h
index a4fddbf..2a51b84 100644
--- a/lib/xalloc.h
+++ b/lib/xalloc.h
@@ -1,6 +1,6 @@
/* xalloc.h -- malloc with out-of-memory checking
- Copyright (C) 1990-2000, 2003-2004, 2006-2016 Free Software Foundation, Inc.
+ Copyright (C) 1990-2000, 2003-2004, 2006-2018 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -13,12 +13,13 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program. If not, see . */
+ along with this program. If not, see . */
#ifndef XALLOC_H_
#define XALLOC_H_
#include
+#include
#include "xalloc-oversized.h"
@@ -193,14 +194,17 @@ x2nrealloc (void *p, size_t *pn, size_t s)
n = DEFAULT_MXFAST / s;
n += !n;
}
+ if (xalloc_oversized (n, s))
+ xalloc_die ();
}
else
{
/* Set N = floor (1.5 * N) + 1 so that progress is made even if N == 0.
- Check for overflow, so that N * S stays in size_t range.
- The check may be slightly conservative, but an exact check isn't
- worth the trouble. */
- if ((size_t) -1 / 3 * 2 / s <= n)
+ Check for overflow, so that N * S stays in both ptrdiff_t and
+ size_t range. The check may be slightly conservative, but an
+ exact check isn't worth the trouble. */
+ if ((PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : SIZE_MAX) / 3 * 2 / s
+ <= n)
xalloc_die ();
n += n / 2 + 1;
}