[syslinux:elflink] exit.c: Truncate exit status to uint8_t

syslinux-bot for Matt Fleming matt.fleming at linux.intel.com
Wed Apr 27 14:31:02 PDT 2011


Commit-ID:  5af736cf7677485da73bdc7ea4633960c8640cb6
Gitweb:     http://syslinux.zytor.com/commit/5af736cf7677485da73bdc7ea4633960c8640cb6
Author:     Matt Fleming <matt.fleming at linux.intel.com>
AuthorDate: Fri, 15 Apr 2011 11:48:37 +0100
Committer:  Matt Fleming <matt.fleming at linux.intel.com>
CommitDate: Tue, 26 Apr 2011 10:05:38 +0100

exit.c: Truncate exit status to uint8_t

The valid range for an exit status is 0 - 255, so we need to truncate
the value passed to _exit().

I noticed this when a module was doing _exit(-1), and ended up calling

	longjmp(.., 0xffffffff + 1)

which meant that setjmp() in spawn_load() returned 0. Obviously, we
wanted the setjmp() to return 256 (0xff + 1), because the code in
spawn_load() handles the return value like so,

		ret_val = setjmp(module->u.x.process_exit);

		if (ret_val)
			ret_val--;              /* Valid range is 0-255 */
		else if (!module->main_func)
			ret_val = -1;
		else
			exit((module->main_func)(argc, argv)); /* Actually run! */

There actually is code in spawn_load() to properly truncate 'ret_val',
but it is applied too late. The truncation needs to happen when we
pass the exit status to longjmp().

Suggested-by: H. Peter Anvin <hpa at zytor.com>
Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com>


---
 com32/lib/exit.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/com32/lib/exit.c b/com32/lib/exit.c
index cba6cee..ebec0a1 100644
--- a/com32/lib/exit.c
+++ b/com32/lib/exit.c
@@ -54,6 +54,6 @@ __noreturn _Exit(int rv)
 
 __noreturn _exit(int rv)
 {
-    longjmp(__syslinux_current->u.x.process_exit, rv+1);
+    longjmp(__syslinux_current->u.x.process_exit, (uint8_t)rv+1);
 }
 



More information about the Syslinux-commits mailing list