From c69ef749eb2a6bcc6fea1025a7e652bc259b8e2e Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Fri, 17 Jan 2020 14:09:43 -0500 Subject: [PATCH] fix host.Info() panic if /etc/debian_version is empty The ReadLines helper function doesn't guarantee that the length of lines is non-zero or that the lines have contents. Most callers include a check for length but this was missing for version fingerprinting on Debian if `/etc/debian_version` was empty, leading to a panic. --- host/host_linux.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/host/host_linux.go b/host/host_linux.go index 272016d..1ef3df6 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -280,7 +280,7 @@ func PlatformInformationWithContext(ctx context.Context) (platform string, famil platform = "debian" } contents, err := common.ReadLines(common.HostEtc("debian_version")) - if err == nil { + if err == nil && len(contents) > 0 && contents[0] != "" { version = contents[0] } } @@ -315,7 +315,7 @@ func PlatformInformationWithContext(ctx context.Context) (platform string, famil } else if common.PathExists(common.HostEtc("alpine-release")) { platform = "alpine" contents, err := common.ReadLines(common.HostEtc("alpine-release")) - if err == nil && len(contents) > 0 { + if err == nil && len(contents) > 0 && contents[0] != "" { version = contents[0] } } else if common.PathExists(common.HostEtc("os-release")) {