summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2020-04-28 20:34:27 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2020-04-28 20:34:27 +0000
commit9f9c9549fd4f7ce362e95e3a8a50f00ffd00175c (patch)
tree282d94b4d469f89ba4cd68c94da01fff9e7c2dd0 /bin
parentfc88ecd31a8093ca1413e25607669864ae540524 (diff)
downloadsrc-test-9f9c9549fd4f7ce362e95e3a8a50f00ffd00175c.tar.gz
src-test-9f9c9549fd4f7ce362e95e3a8a50f00ffd00175c.zip
sh: Assert INTOFF rather than applying it in ck*
As I noted in https://reviews.freebsd.org/D22756, INTOFF should be in effect when calling ckmalloc/ckrealloc/ckfree to avoid memory leaks and double frees. Therefore, change the functions to check if INTOFF is in effect instead of applying it. Reviewed by: bdrewery Differential Revision: https://reviews.freebsd.org/D24599
Notes
Notes: svn path=/head/; revision=360452
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/memalloc.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/bin/sh/memalloc.c b/bin/sh/memalloc.c
index 58d1be8ccd4ea..a2191771386dc 100644
--- a/bin/sh/memalloc.c
+++ b/bin/sh/memalloc.c
@@ -50,6 +50,13 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <unistd.h>
+static void
+badalloc(const char *message)
+{
+ write(2, message, strlen(message));
+ abort();
+}
+
/*
* Like malloc, but returns an error when out of space.
*/
@@ -59,9 +66,9 @@ ckmalloc(size_t nbytes)
{
pointer p;
- INTOFF;
+ if (!is_int_on())
+ badalloc("Unsafe ckmalloc() call\n");
p = malloc(nbytes);
- INTON;
if (p == NULL)
error("Out of space");
return p;
@@ -75,9 +82,9 @@ ckmalloc(size_t nbytes)
pointer
ckrealloc(pointer p, int nbytes)
{
- INTOFF;
+ if (!is_int_on())
+ badalloc("Unsafe ckrealloc() call\n");
p = realloc(p, nbytes);
- INTON;
if (p == NULL)
error("Out of space");
return p;
@@ -86,9 +93,9 @@ ckrealloc(pointer p, int nbytes)
void
ckfree(pointer p)
{
- INTOFF;
+ if (!is_int_on())
+ badalloc("Unsafe ckfree() call\n");
free(p);
- INTON;
}