aboutsummaryrefslogtreecommitdiffstats
path: root/main/apk-tools/0001-list-fix-segmentation-fault-with-virtual-packages.patch
blob: 883d7bb86c2511bb55310066ae554b98d6bd0e44 (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
39
40
41
42
43
44
45
46
From 5c4b90dfd48d476b9e7aae2ad6627dd6f03ac557 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
Date: Fri, 29 Jun 2018 15:39:56 +0200
Subject: [PATCH] list: fix segmentation fault with virtual packages

Virtual packages have the origin pointer set to NULL. Trying to print it
using the BLOB_PRINTF macros causes a segmentation fault.

Inspired by the `print_origin_name` function from `src/search.c` this
commit attempts to fix it by checking whether `pkg->origin` is NULL
before attempting to print it. If it is NULL the pkg name is printed
instead.

Since printing the pkg name requires a different format string this
commit splits the printf call for printing the package line into
multiple ones. The output format shouldn't have changed at all though.
---
 src/list.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/list.c b/src/list.c
index 14f5fb5..e285e3f 100644
--- a/src/list.c
+++ b/src/list.c
@@ -101,9 +101,15 @@ static const struct apk_package *is_upgradable(struct apk_name *name, const stru
 
 static void print_package(const struct apk_package *pkg, const struct list_ctx *ctx)
 {
-	printf(PKG_VER_FMT " " BLOB_FMT " {" BLOB_FMT "} (" BLOB_FMT ")",
-		PKG_VER_PRINTF(pkg), BLOB_PRINTF(*pkg->arch), BLOB_PRINTF(*pkg->origin),
-		BLOB_PRINTF(*pkg->license));
+	printf(PKG_VER_FMT " " BLOB_FMT " ",
+		PKG_VER_PRINTF(pkg), BLOB_PRINTF(*pkg->arch));
+
+	if (pkg->origin != NULL)
+		printf("{" BLOB_FMT "}", BLOB_PRINTF(*pkg->origin));
+	else
+		printf("{%s}", pkg->name->name);
+
+	printf(" (" BLOB_FMT ")", BLOB_PRINTF(*pkg->license));
 
 	if (pkg->ipkg)
 		printf(" [installed]");
-- 
2.18.0