From a4d32450c3565f5dba9e027283ea3dd40a21138e Mon Sep 17 00:00:00 2001 From: Denis 'GNUtoo' Carikli Date: Mon, 9 Jan 2017 21:50:19 +0100 Subject: [PATCH 41/43] osutils: don't segfault on empty files. In the "string operating_system()" method, the GNU/Linux distribution is detected by trying to open various files like /etc/lsb_release. Without that patch, If one of such file is present and empty, lshw -dump will produce a segmentation fault. On the Parabola GNU/Linux distribution (An arch derivative), /etc/arch-release is empty. Signed-off-by: Denis 'GNUtoo' Carikli --- src/core/osutils.cc | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/core/osutils.cc b/src/core/osutils.cc index cc03dc4..e93b79e 100644 --- a/src/core/osutils.cc +++ b/src/core/osutils.cc @@ -773,47 +773,47 @@ string operating_system() struct utsname u; string os = ""; - if(loadfile("/etc/lsb-release", osinfo)) + if(loadfile("/etc/lsb-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/lsb_release", osinfo)) + else if(loadfile("/etc/lsb_release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/system-release", osinfo)) + else if(loadfile("/etc/system-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/release", osinfo)) + else if(loadfile("/etc/release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/arch-release", osinfo)) + else if(loadfile("/etc/arch-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/arklinux-release", osinfo)) + else if(loadfile("/etc/arklinux-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/aurox-release", osinfo)) + else if(loadfile("/etc/aurox-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/conectiva-release", osinfo)) + else if(loadfile("/etc/conectiva-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/debian_version", osinfo)) + else if(loadfile("/etc/debian_version", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/fedora-release", osinfo)) + else if(loadfile("/etc/fedora-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/gentoo-release", osinfo)) + else if(loadfile("/etc/gentoo-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/linuxppc-release", osinfo)) + else if(loadfile("/etc/linuxppc-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/mandrake-release", osinfo)) + else if(loadfile("/etc/mandrake-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/mandriva-release", osinfo)) + else if(loadfile("/etc/mandriva-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/novell-release", osinfo)) + else if(loadfile("/etc/novell-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/pld-release", osinfo)) + else if(loadfile("/etc/pld-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/redhat-release", osinfo)) + else if(loadfile("/etc/redhat-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/slackware-version", osinfo)) + else if(loadfile("/etc/slackware-version", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/sun-release", osinfo)) + else if(loadfile("/etc/sun-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/SuSE-release", osinfo)) + else if(loadfile("/etc/SuSE-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; - else if(loadfile("/etc/yellowdog-release", osinfo)) + else if(loadfile("/etc/yellowdog-release", osinfo) && (osinfo.size() > 0)) os = osinfo[0]; if(uname(&u) != 0) return ""; -- 2.10.2