aboutsummaryrefslogtreecommitdiff
path: root/src/lib/kmem.c
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-02-04 18:30:32 -0700
committerChristian Cunningham <cc@localhost>2022-02-04 18:30:32 -0700
commit3e0cf15954f8f65e975d4af7b8ac659d37bc5377 (patch)
treeb00b3074c326b1f160f1065717d90b95abd441f5 /src/lib/kmem.c
parentce24526da5c66f1840721707023ae4ecab51486e (diff)
Prevent freeing non-kmem
Diffstat (limited to 'src/lib/kmem.c')
-rw-r--r--src/lib/kmem.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/lib/kmem.c b/src/lib/kmem.c
index 5fda56a..a3d0740 100644
--- a/src/lib/kmem.c
+++ b/src/lib/kmem.c
@@ -36,7 +36,7 @@ void* kcalloc(unsigned int size)
void* krealloc(void* old, unsigned int size)
{
- if (!(kmem_begin <= old && old < kmem_begin + 0x200000))
+ if (!((unsigned long)kmem_begin <= (unsigned long)old && (unsigned long)old < (unsigned long)kmem_begin + 0x200000))
return 0;
unsigned long old_size = 1;
while (!((unsigned long)kmem_begin + 0x1000*(old_size/2) <= (unsigned long)old && (unsigned long)old < (unsigned long)kmem_begin + 0x1000*old_size))
@@ -61,6 +61,8 @@ void* krealloc(void* old, unsigned int size)
void kfree(void* ptr)
{
+ if (!((unsigned long)kmem_begin <= (unsigned long)ptr && (unsigned long)ptr < (unsigned long)kmem_begin + 0x200000))
+ return 0;
unsigned long size = 1;
while (!((unsigned long)kmem_begin + 0x1000*(size/2) <= (unsigned long)ptr && (unsigned long)ptr < (unsigned long)kmem_begin + 0x1000*size)) {
size *= 2;