summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core
diff options
context:
space:
mode:
authorVyacheslav Yurkov <uvv.mail@gmail.com>2020-04-30 16:03:40 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-05-14 16:45:42 +0100
commitc288352cee5ad7163800e3c74f2c2a50ee8ddb95 (patch)
treea2b2bfa5ca4250371d3dcb77a83275322a41a51f /meta/recipes-core
parente328ec317ed2a09a4304f7325ea1bf2fec826f47 (diff)
downloadpoky-c288352cee5ad7163800e3c74f2c2a50ee8ddb95.tar.gz
os-release: sanitize required fields
Currently only VERSION_ID field is sanitized, but os-release (5) has more fields with the same requirement. Moreover, those fields come unquoted in most distributions, because quotes are not needed for a values without whitespaces. (From OE-Core rev: ea39b2edecc00cc2340328893cdfbefed5d3b981) Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-core')
-rw-r--r--meta/recipes-core/os-release/os-release.bb14
1 files changed, 9 insertions, 5 deletions
diff --git a/meta/recipes-core/os-release/os-release.bb b/meta/recipes-core/os-release/os-release.bb
index d5793c6fed..a29d678125 100644
--- a/meta/recipes-core/os-release/os-release.bb
+++ b/meta/recipes-core/os-release/os-release.bb
@@ -13,6 +13,7 @@ do_configure[noexec] = "1"
13# Other valid fields: BUILD_ID ID_LIKE ANSI_COLOR CPE_NAME 13# Other valid fields: BUILD_ID ID_LIKE ANSI_COLOR CPE_NAME
14# HOME_URL SUPPORT_URL BUG_REPORT_URL 14# HOME_URL SUPPORT_URL BUG_REPORT_URL
15OS_RELEASE_FIELDS = "ID ID_LIKE NAME VERSION VERSION_ID PRETTY_NAME" 15OS_RELEASE_FIELDS = "ID ID_LIKE NAME VERSION VERSION_ID PRETTY_NAME"
16OS_RELEASE_UNQUOTED_FIELDS = "ID VERSION_ID VARIANT_ID"
16 17
17ID = "${DISTRO}" 18ID = "${DISTRO}"
18NAME = "${DISTRO_NAME}" 19NAME = "${DISTRO_NAME}"
@@ -22,8 +23,8 @@ PRETTY_NAME = "${DISTRO_NAME} ${VERSION}"
22BUILD_ID ?= "${DATETIME}" 23BUILD_ID ?= "${DATETIME}"
23BUILD_ID[vardepsexclude] = "DATETIME" 24BUILD_ID[vardepsexclude] = "DATETIME"
24 25
25def sanitise_version(ver): 26def sanitise_value(ver):
26 # VERSION_ID should be (from os-release(5)): 27 # unquoted fields like VERSION_ID should be (from os-release(5)):
27 # lower-case string (mostly numeric, no spaces or other characters 28 # lower-case string (mostly numeric, no spaces or other characters
28 # outside of 0-9, a-z, ".", "_" and "-") 29 # outside of 0-9, a-z, ".", "_" and "-")
29 ret = ver.replace('+', '-').replace(' ','_') 30 ret = ver.replace('+', '-').replace(' ','_')
@@ -32,11 +33,14 @@ def sanitise_version(ver):
32python do_compile () { 33python do_compile () {
33 with open(d.expand('${B}/os-release'), 'w') as f: 34 with open(d.expand('${B}/os-release'), 'w') as f:
34 for field in d.getVar('OS_RELEASE_FIELDS').split(): 35 for field in d.getVar('OS_RELEASE_FIELDS').split():
36 unquotedFields = d.getVar('OS_RELEASE_UNQUOTED_FIELDS').split()
35 value = d.getVar(field) 37 value = d.getVar(field)
36 if value and field == 'VERSION_ID':
37 value = sanitise_version(value)
38 if value: 38 if value:
39 f.write('{0}="{1}"\n'.format(field, value)) 39 if field in unquotedFields:
40 value = sanitise_value(value)
41 f.write('{0}={1}\n'.format(field, value))
42 else:
43 f.write('{0}="{1}"\n'.format(field, value))
40} 44}
41do_compile[vardeps] += "${OS_RELEASE_FIELDS}" 45do_compile[vardeps] += "${OS_RELEASE_FIELDS}"
42 46