DragonFly bugs List (threaded) for 2009-05
DragonFly BSD
DragonFly bugs List (threaded) for 2009-05
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: zero-size malloc and ps: kvm_getprocs: Bad address

From: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 24 May 2009 10:11:45 -0700 (PDT)

    We currently return an invalid non-NULL pointer, ZERO_LENGTH_PTR,
    which I have set to ((void *)-8).

    We can change ZERO_LENGTH_PTR to be whatever we want, including
    making it a pointer to valid memory like the address of a dummy

    It might be better to fix kvm_getprocs, though, to not try to do a
    useracc test on a zero-length allocation.  But I leave it up to you

					Matthew Dillon 

diff --git a/lib/libc/stdlib/nmalloc.c b/lib/libc/stdlib/nmalloc.c
index faa1e5c..29c1c4f 100644
--- a/lib/libc/stdlib/nmalloc.c
+++ b/lib/libc/stdlib/nmalloc.c
@@ -183,7 +183,7 @@ typedef struct slglobaldata {
 #define WEIRD_ADDR      0xdeadc0de
 #define MAX_COPY        sizeof(weirdary)
-#define ZERO_LENGTH_PTR	((void *)-8)
+#define ZERO_LENGTH_PTR	((void *)&nmalloc_dummy_storage)
 #define BIGHSHIFT	10			/* bigalloc hash table */
 #define BIGHSIZE	(1 << BIGHSHIFT)
@@ -219,6 +219,7 @@ static struct slglobaldata	SLGlobalData[SLGD_MAX];
 static bigalloc_t bigalloc_array[BIGHSIZE];
 static spinlock_t bigspin_array[BIGXSIZE];
 static int malloc_panic;
+static int nmalloc_dummy_storage;
 static const int32_t weirdary[16] = {

[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]