hiredis/fix-mem_size-overflow.patch
2021-12-20 10:29:19 +08:00

42 lines
897 B
Diff

From 299246408d3442a3240ccf25ce31c08ecee64766 Mon Sep 17 00:00:00 2001
From: wu-leilei <wu18740459704@163.com>
Date: Mon, 20 Dec 2021 10:14:35 +0800
Subject: [PATCH] fix mem_size overflow
---
alloc.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/alloc.h b/alloc.h
index 34a05f4..89cb727 100644
--- a/alloc.h
+++ b/alloc.h
@@ -33,6 +33,11 @@
#include <stddef.h> /* for size_t */
+#ifndef _WIN32
+#include <sys/sysinfo.h>
+#include <linux/kernel.h>
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -55,6 +60,12 @@ void hiredisResetAllocators(void);
extern hiredisAllocFuncs hiredisAllocFns;
static inline void *hi_malloc(size_t size) {
+#ifndef _WIN32
+ struct sysinfo s_info;
+ int error;
+ if((error = sysinfo(&s_info)) < 0) return NULL;
+ if(s_info.totalram < size) return NULL;
+#endif
return hiredisAllocFns.mallocFn(size);
}
--
2.23.0