[B.A.T.M.A.N.] [PATCH 4/6] batctl: Return success only with valid line_ptr in read_file

Sven Eckelmann sven at narfation.org
Sat May 24 14:16:42 CEST 2014


The read_file function is rather complex and cluttered with different
functionality. One of it is to provide a line_ptr of a single line to the
caller. The caller trusts the return code for a SUCCESS of this function
and tries to access the line_ptr. But a failed getline may lead to an
NULL-line_ptr. The caller tries to dereference this NULL pointer and
causes an segfault.

Signed-off-by: Sven Eckelmann <sven at narfation.org>
---
 functions.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/functions.c b/functions.c
index 84f0d14..251e616 100644
--- a/functions.c
+++ b/functions.c
@@ -320,7 +320,8 @@ written:
 		goto open;
 	}
 
-	res = EXIT_SUCCESS;
+	if (line_ptr)
+		res = EXIT_SUCCESS;
 
 out:
 	if (fp)
-- 
2.0.0.rc2



More information about the B.A.T.M.A.N mailing list