aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-core/swupd-client/swupd-client-2.87/0001-Tolerate-quotes-in-os-release-files.patch
blob: c5faae87ad5ffc3cecfb19ae0b5944b0eeece6fe (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
From 0ac7226645db1c7048863755a296e1e5f7d8319c Mon Sep 17 00:00:00 2001
From: Dmitry Rozhkov <dmitry.rozhkov@intel.com>
Date: Thu, 11 Feb 2016 12:49:30 +0200
Subject: [PATCH] Tolerate quotes in os-release files

Some systems like Yocto or OpenSUSE prefer to wrap values in
/etc/os-release file with quotes always and that still conforms
to the format defined in systemd.

This patch removes quotes from the values before trying to
transform them into integer version id.

Upstream-Status: Backport (v3.0.0+)

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@intel.com>
---
 src/version.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/version.c b/src/version.c
index d8ad76b..1708a98 100644
--- a/src/version.c
+++ b/src/version.c
@@ -95,6 +95,7 @@ int read_version_from_subvol_file(char *path_prefix)
 	FILE *file;
 	int v = -1;
 	char *buildstamp;
+	char *src, *dest;
 
 	string_or_die(&buildstamp, "%s/usr/lib/os-release", path_prefix);
 	file = fopen(buildstamp, "rm");
@@ -116,7 +117,22 @@ int read_version_from_subvol_file(char *path_prefix)
 		if (fgets(line, LINE_MAX, file) == NULL)
 			break;
 
-		if (strncmp(line,"VERSION_ID=", 11) == 0) {
+		if (strncmp(line, "VERSION_ID=", 11) == 0) {
+			src = &line[11];
+
+			/* Drop quotes and newline in value */
+			dest = src;
+			while (*src) {
+				if (*src == '\'' || *src == '"' || *src == '\n') {
+					++src;
+				} else {
+					*dest = *src;
+					++dest;
+					++src;
+				}
+			}
+			*dest = 0;
+
 			v = strtoull(&line[11], NULL, 10);
 			break;
 		}
-- 
2.5.0