aboutsummaryrefslogtreecommitdiffstats
path: root/main/util-linux/0001-libblkid-Fix-segfault-when-blkid.conf-doesn-t-exist.patch
blob: b1d83c05a6fce73247027a6000804a0cd88c8dfc (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
From 7e357241b413a01c37b0b4d064bc0a47e3259361 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Mon, 1 Apr 2024 12:14:50 +0200
Subject: [PATCH] libblkid: Fix segfault when blkid.conf doesn't exist

* Move 'line' and 'uevent' to the beginning of the LIBECONF code.
* Remove unwanted space between function name and arguments.
* Check for 'line' pointer before dereferencing.

References: https://github.com/util-linux/util-linux/pull/2883
Signed-off-by: Karel Zak <kzak@redhat.com>
---
 libblkid/src/config.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libblkid/src/config.c b/libblkid/src/config.c
index 7b8b04f92..66c1864f0 100644
--- a/libblkid/src/config.c
+++ b/libblkid/src/config.c
@@ -153,6 +153,8 @@ struct blkid_config *blkid_read_config(const char *filename)
 #else /* !HAVE_LIBECONF */
 
 	static econf_file *file = NULL;
+	char *line = NULL;
+	bool uevent = false;
 	econf_err error;
 
 	if (filename) {
@@ -187,7 +189,6 @@ struct blkid_config *blkid_read_config(const char *filename)
 		}
 	}
 
-	bool uevent = false;
 	if ((error = econf_getBoolValue(file, NULL, "SEND_UEVENT", &uevent))) {
 		if (error != ECONF_NOKEY) {
 			DBG(CONFIG, ul_debug("couldn't fetch SEND_UEVENT corrently: %s", econf_errString(error)));
@@ -209,7 +210,6 @@ struct blkid_config *blkid_read_config(const char *filename)
 		}
 	}
 
-	char *line = NULL;
 	if ((error = econf_getStringValue(file, NULL, "EVALUATE", &line))) {
 		conf->nevals = 0;
 		if (error != ECONF_NOKEY) {
@@ -219,7 +219,7 @@ struct blkid_config *blkid_read_config(const char *filename)
 			DBG(CONFIG, ul_debug("key CACHE_FILE not found, using built-in default "));
 		}
 	} else {
-		if (*line && parse_evaluate(conf, line) == -1)
+		if (line && *line && parse_evaluate(conf, line) == -1)
 			goto err;
 	}
 
@@ -238,8 +238,8 @@ dflt:
 	if (f)
 		fclose(f);
 #else
-	econf_free (file);
-	free (line);
+	econf_free(file);
+	free(line);
 #endif
 	return conf;
 err:
@@ -248,8 +248,8 @@ err:
 #ifndef HAVE_LIBECONF
 	fclose(f);
 #else
-	econf_free (file);
-	free (line);
+	econf_free(file);
+	free(line);
 #endif
 	return NULL;
 }
-- 
2.44.0