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.
pull/822/head
Tim Gross 5 years ago
parent bcf28f0c37
commit c69ef749eb

@ -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")) {

Loading…
Cancel
Save