[Spice-devel] [PATCH] Abort if mmap of coroutine stack fails

Daniel P. Berrange berrange at redhat.com
Fri Sep 13 05:30:04 PDT 2013


From: "Daniel P. Berrange" <berrange at redhat.com>

If we fail to mmap the stack, abort the processs rather
than returning an error. This is standard practice in
glib apps, and the caller was not checking the
coroutine_init() return code leading to memory corruption.

Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
---
 gtk/coroutine_ucontext.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gtk/coroutine_ucontext.c b/gtk/coroutine_ucontext.c
index af811a7..79e4afe 100644
--- a/gtk/coroutine_ucontext.c
+++ b/gtk/coroutine_ucontext.c
@@ -20,6 +20,7 @@
 
 #include <config.h>
 
+#include <glib.h>
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
@@ -69,7 +70,8 @@ int coroutine_init(struct coroutine *co)
 			    MAP_PRIVATE | MAP_ANONYMOUS,
 			    -1, 0);
 	if (co->cc.stack == MAP_FAILED)
-		return -1;
+		g_error("Failed to allocate %u bytes for coroutine stack",
+			(unsigned)co->stack_size);
 	co->cc.entry = coroutine_trampoline;
 	co->cc.release = _coroutine_release;
 	co->exited = 0;
-- 
1.8.3.1



More information about the Spice-devel mailing list