summaryrefslogtreecommitdiffstats
path: root/main/apk-tools/0001-db-fix-segfault-when-root-points-to-invalid-dir.patch
blob: ddb1802beadcd590904ce652d6124b07632cb2c4 (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
From 50eef05ce75eaf9a14afb2d855fdf27e3d3ce69f Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Tue, 16 Jul 2013 06:26:12 +0000
Subject: [PATCH 1/2] db: fix segfault when --root points to invalid dir

fixes #2134
---
 src/database.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/database.c b/src/database.c
index 33f7af8..d8b84b5 100644
--- a/src/database.c
+++ b/src/database.c
@@ -1740,7 +1740,9 @@ void apk_db_close(struct apk_database *db)
 	struct hlist_node *dc, *dn;
 	int i;
 
-	apk_id_cache_free(&db->id_cache);
+	/* the id cache was never initialized if root_fd failed */
+	if (db->root_fd >= 0)
+		apk_id_cache_free(&db->id_cache);
 
 	/* Cleaning up the directory tree will cause mode, uid and gid
 	 * of all modified (package providing that directory got removed)
-- 
1.8.3.2