Skip to content

Commit

Permalink
Fix malformed uname string (prometheus#2727)
Browse files Browse the repository at this point in the history
* Fix malformed uname string

* Make fix better

* Reformat code for simplicity
  • Loading branch information
Shashank Varanasi authored and fabxc committed May 16, 2017
1 parent 713fef2 commit dea60bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmd/prometheus/uname_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func Uname() string {
if err != nil {
log.Fatal("Error!")
}

str := "(" + charsToString(buf.Sysname[:])
str += " " + charsToString(buf.Release[:])
str += " " + charsToString(buf.Version[:])
Expand Down
11 changes: 7 additions & 4 deletions cmd/prometheus/uname_linux_int8.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
package main

func charsToString(ca []int8) string {
s := make([]byte, len(ca))
for i, c := range ca {
s[i] = byte(c)
s := make([]byte, 0, len(ca))
for _, c := range ca {
if byte(c) == 0 {
break
}
s = append(s, byte(c))
}
return string(s[0:len(ca)])
return string(s)
}
11 changes: 7 additions & 4 deletions cmd/prometheus/uname_linux_uint8.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
package main

func charsToString(ca []uint8) string {
s := make([]byte, len(ca))
for i, c := range ca {
s[i] = byte(c)
s := make([]byte, 0, len(ca))
for _, c := range ca {
if byte(c) == 0 {
break
}
s = append(s, byte(c))
}
return string(s[0:len(ca)])
return string(s)
}

0 comments on commit dea60bb

Please sign in to comment.