aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-core/swupd-client/swupd-client-2.87/0001-log.c-avoid-segfault-and-show-staging-file-name.patch
blob: 424a3bd3cb7409bc68592cfe34b0ea524686b8f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
From 03ea6060f2992fffe242d0af769b7550a014c28f Mon Sep 17 00:00:00 2001
From: Patrick Ohly <patrick.ohly@intel.com>
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 <patrick.ohly@intel.com>
---
 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