From 1526a19e5584e4addf56fdf70d52ccd89daf5dbb Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Thu, 4 May 2017 19:03:25 +0200 Subject: [PATCH] Fix stripping GNU/Linux from DistroRelease The DistroRelease contains GNU/Linux on Debian (example: "Debian GNU/Linux 8"). The containing slash is very confusing when using the DistroRelease as path. name[1:-2] strips one leading characters and two trailing characters and removes one character too much at the end. Thus the name.endswith check fails to match 'GNU/Linux' and does nothing. If it was matching GNU/Linux, it would set name to a list. Fix the parsing of /etc/os-release by using shlex. LP: #1684600 --- apport/packaging.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/apport/packaging.py b/apport/packaging.py index cf91b0345..c981515c0 100644 --- a/apport/packaging.py +++ b/apport/packaging.py @@ -12,6 +12,7 @@ import os import sys import re +import shlex import subprocess @@ -284,17 +285,12 @@ class PackageInfo: version = None with open('/etc/os-release') as f: for l in f: - if l.startswith('NAME='): - name = l.split('=', 1)[1] - if name.startswith('"'): - name = name[1:-2].strip() - # work around inconsistent "Debian GNU/Linux" in os-release - if name.endswith('GNU/Linux'): - name = name.split()[0:-1] - elif l.startswith('VERSION_ID='): - version = l.split('=', 1)[1] - if version.startswith('"'): - version = version[1:-2].strip() + key, value = shlex.split(l)[0].split('=', 1) + if key == 'NAME': + # The OS name might be used as path later. Thus avoid / in the name. + name = value[:-9].strip() if value.endswith('GNU/Linux') else value + if key == 'VERSION_ID': + version = value if name and version: self._os_version = (name, version) return self._os_version -- 2.11.0