git » libfiu » commit b96717b

libfiu: Fix backtrace_works() in fiu_enable_stack_by_name()

author Alberto Bertogli
2012-09-04 23:44:51 UTC
committer Alberto Bertogli
2012-09-04 23:48:23 UTC
parent 2be43a71b7e32dcd0489ee70667aa0898a9f645a

libfiu: Fix backtrace_works() in fiu_enable_stack_by_name()

fiu_enable_stack_by_name() calls fiu_enable_stack(), which does the
backtrace_works() check.

For that check to work, fiu_enable_stack() must be on the stack. However, when
fiu_enable_stack_by_name() invokes it, it could be inlined, causing the check
to fail.

This patch adds an independent backtrace_works() check within
fiu_enable_stack_by_name(), so we're sure the caller is on the stack.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

libfiu/fiu.c +6 -0

diff --git a/libfiu/fiu.c b/libfiu/fiu.c
index d9ea787..68cab04 100644
--- a/libfiu/fiu.c
+++ b/libfiu/fiu.c
@@ -540,6 +540,12 @@ int fiu_enable_stack_by_name(const char *name, int failnum, void *failinfo,
 {
 	void *fp;
 
+	/* We need to check this here instead of relying on the test within
+	 * fiu_enable_stack() in case it is inlined; that would fail the check
+	 * because fiu_enable_stack() would not be in the stack. */
+	if (backtrace_works((void (*)()) fiu_enable_stack_by_name) == 0)
+		return -1;
+
 	fp = get_func_addr(func_name);
 	if (fp == NULL)
 		return -1;