git » libfiu » commit 59ab15c

libfiu: Do not crash if fiu_fail() is run before fiu_init()

author Alberto Bertogli
2013-10-11 01:42:55 UTC
committer Alberto Bertogli
2013-10-29 02:12:10 UTC
parent 92c7a331da5816e2718c076124db5d0abe38feb7

libfiu: Do not crash if fiu_fail() is run before fiu_init()

Under some circumstances (e.g. some preload invocations) it can happen that
fiu_fail() gets called before fiu_init().

In that case, our enabled_fails table is NULL, so we shouldn't try to access
it. This patch changes fiu_fail() to do that.

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 5d53e82..ce89112 100644
--- a/libfiu/fiu.c
+++ b/libfiu/fiu.c
@@ -265,6 +265,12 @@ int fiu_fail(const char *name)
 
 	ef_rlock();
 
+	/* It can happen that someone calls fiu_fail() before fiu_init(); we
+	 * don't want to crash so we just exit. */
+	if (enabled_fails == NULL) {
+		goto exit;
+	}
+
 	pf = wtable_get(enabled_fails, name);
 
 	/* None found. */