[PATCH] mm/util.c: add a none zero check of "len"

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

 



Although this check should have been done by caller. But as it's exported to others,
It's better to add a none zero check of "len" like other functions.

Signed-off-by: xinhuix.pan <xinhuix.pan@xxxxxxxxx>
---
 mm/util.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm/util.c b/mm/util.c
index fec39d4..3dc2873 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -72,6 +72,9 @@ void *kmemdup(const void *src, size_t len, gfp_t gfp)
 {
 	void *p;
+ if (unlikely(!len))
+		return ERR_PTR(-EINVAL);
+
 	p = kmalloc_track_caller(len, gfp);
 	if (p)
 		memcpy(p, src, len);
@@ -91,6 +94,8 @@ void *memdup_user(const void __user *src, size_t len)
 {
 	void *p;
+ if (unlikely(!len))
+		return ERR_PTR(-EINVAL);
 	/*
 	 * Always use GFP_KERNEL, since copy_from_user() can sleep and
 	 * cause pagefault, which makes it pointless to use GFP_NOFS
--
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]