Added length checks when extracting versions in case the files have been edited
@@ -85,9 +85,11 @@ func getPlatformDetails(log log.T) (name string, version string, err error) {
if strings.Contains(contents, "CentOS") {
data := strings.Split(contents, "release")
name = strings.TrimSpace(data[0])
+ if len(data) >= 2 {
versionData := strings.Split(data[1], "(")
version = strings.TrimSpace(versionData[0])
}
+ }
} else if fileutil.Exists(osReleaseFile) {
log.Debugf(fetchingDetailsMessage, osReleaseFile)
@@ -117,28 +119,40 @@ func getPlatformDetails(log log.T) (name string, version string, err error) {
if strings.Contains(contents, "Amazon") {
data := strings.Split(contents, "release")
name = strings.TrimSpace(data[0])
+ if len(data) >= 2 {
version = strings.TrimSpace(data[1])
+ }
} else if strings.Contains(contents, "Red Hat") {
data := strings.Split(contents, "release")
name = strings.TrimSpace(data[0])
+ if len(data) >= 2 {
version = strings.TrimSpace(data[1])
+ }
} else if strings.Contains(contents, "CentOS") {
data := strings.Split(contents, "release")
name = strings.TrimSpace(data[0])
+ if len(data) >= 2 {
version = strings.TrimSpace(data[1])
+ }
} else if strings.Contains(contents, "SLES") {
data := strings.Split(contents, "release")
name = strings.TrimSpace(data[0])
+ if len(data) >= 2 {
version = strings.TrimSpace(data[1])
+ }
} else if strings.Contains(contents, "Raspbian") {
data := strings.Split(contents, "release")
name = strings.TrimSpace(data[0])
+ if len(data) >= 2 {
version = strings.TrimSpace(data[1])
+ }
} else if strings.Contains(contents, "Oracle") {
data := strings.Split(contents, "release")
name = strings.TrimSpace(data[0])
+ if len(data) >= 2 {
version = strings.TrimSpace(data[1])
}
+ }
} else if fileutil.Exists(redhatReleaseFile) {
log.Debugf(fetchingDetailsMessage, redhatReleaseFile)
@@ -152,9 +166,11 @@ func getPlatformDetails(log log.T) (name string, version string, err error) {
if strings.Contains(contents, "Red Hat") {
data := strings.Split(contents, "release")
name = strings.TrimSpace(data[0])
+ if len(data) >= 2 {
versionData := strings.Split(data[1], "(")
version = strings.TrimSpace(versionData[0])
}
+ }
} else if runtime.GOOS == "freebsd" {
log.Debugf(fetchingDetailsMessage, unameCommand)
@@ -166,7 +182,9 @@ func getPlatformDetails(log log.T) (name string, version string, err error) {
data := strings.Split(string(contentsBytes), " ")
name = strings.TrimSpace(data[0])
+ if len(data) >= 2 {
version = strings.TrimSpace(data[1])
+ }
} else {
log.Debugf(fetchingDetailsMessage, lsbReleaseCommand)
