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@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)