From 03ea6060f2992fffe242d0af769b7550a014c28f Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 14 Apr 2016 11:01:10 +0200 Subject: [PATCH 1/2] log.c: avoid segfault and show staging file name When downloading files, "file->filename" is not set, only "file->staging" is. Now the code checks both, starting with "file->filename", and proceeds if both are unset, instead of segfaulting as before. Upstream-Status: Submitted [https://github.com/clearlinux/swupd-client/issues/37] Signed-off-by: Patrick Ohly --- src/log.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/log.c b/src/log.c index 5e5b030..0549f29 100644 --- a/src/log.c +++ b/src/log.c @@ -413,8 +413,11 @@ static char *format_log_message(int log_type, enum log_priority priority, struct filebuf2[0] = 0; strncpy(filebuf, filename, PATH_MAXLEN - 1); if (file) { - strncpy(filebuf2, file->filename, PATH_MAXLEN - 1); - filebuf2[PATH_MAXLEN - 1] = 0; + const char *filename = file->filename ? file->filename : file->staging; + if (filename) { + strncpy(filebuf2, filename, PATH_MAXLEN - 1); + filebuf2[PATH_MAXLEN - 1] = 0; + } } while (strlen(filebuf) < 29) strcat(filebuf, " "); -- 2.1.4