From ada5a789364f52cc93ba64225b74a9ee37ad99a8 Mon Sep 17 00:00:00 2001 From: rls1004 <98nba@naver.com> Date: Mon, 9 Sep 2019 09:57:01 +0000 Subject: [PATCH] uftrace: Fix segfault when given logfile name is already taken by a directory This patch is to fix segfault in --logfile. If logfd is NULL, set logfd to stderr before calling pr_err(). Fixed: #853 --- uftrace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/uftrace.c b/uftrace.c index 536d33b2f..099e8bbef 100644 --- a/uftrace.c +++ b/uftrace.c @@ -1082,8 +1082,10 @@ int main(int argc, char *argv[]) if (opts.logfile) { logfp = fopen(opts.logfile, "a"); - if (logfp == NULL) + if (logfp == NULL) { + logfp = stderr; pr_err("cannot open log file"); + } setvbuf(logfp, NULL, _IOLBF, 1024); }