public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v2] alloc: Add memalign error checks
@ 2019-11-04 10:29 Janosch Frank
  2019-11-04 10:33 ` David Hildenbrand
  0 siblings, 1 reply; 10+ messages in thread
From: Janosch Frank @ 2019-11-04 10:29 UTC (permalink / raw)
  To: kvm; +Cc: thuth, david, pbonzini

Let's test for size and alignment in memalign to catch invalid input
data. Also we need to test for NULL after calling the memalign
function of the registered alloc operations.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 lib/alloc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/alloc.c b/lib/alloc.c
index ecdbbc4..b763c70 100644
--- a/lib/alloc.c
+++ b/lib/alloc.c
@@ -47,6 +47,8 @@ void *memalign(size_t alignment, size_t size)
 	uintptr_t mem;
 
 	assert(alloc_ops && alloc_ops->memalign);
+	if (!size || !alignment)
+		return NULL;
 	if (alignment <= sizeof(uintptr_t))
 		alignment = sizeof(uintptr_t);
 	else
@@ -55,6 +57,7 @@ void *memalign(size_t alignment, size_t size)
 	blkalign = MAX(alignment, alloc_ops->align_min);
 	size = ALIGN(size + METADATA_EXTRA, alloc_ops->align_min);
 	p = alloc_ops->memalign(blkalign, size);
+	assert(p);
 
 	/* Leave room for metadata before aligning the result.  */
 	mem = (uintptr_t)p + METADATA_EXTRA;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-11-11 13:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-04 10:29 [kvm-unit-tests PATCH v2] alloc: Add memalign error checks Janosch Frank
2019-11-04 10:33 ` David Hildenbrand
2019-11-04 10:54   ` Andrew Jones
2019-11-04 11:29     ` Paolo Bonzini
2019-11-04 11:31       ` David Hildenbrand
2019-11-11 10:12       ` Janosch Frank
2019-11-11 12:31         ` Andrew Jones
2019-11-11 13:04           ` Paolo Bonzini
2019-11-11 13:13             ` Janosch Frank
2019-11-11 13:17               ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox