New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/sys/unix: invalid data returned by (syscall|unix).Sysctl() on (at least) FreeBSD 11 (amd64) and NetBSD 7 (i386) #18965
Comments
I only skimmed this bug report, but wanted to say that any fix probably belongs in https://godoc.org/golang.org/x/sys/unix instead of the syscall package, which is frozen. |
/cc @mdempsky |
fair enough, but for the record, it happens with golang.org/x/sys/unix as well. I'll file a second report if that's the best course of action, but you can see below it's the same behaviour:
|
syscall.Sysctl is just returning the raw byte data returned by the OS. []byte{0, 240, 118, 127} is the little-endian encoding of 2138501120. |
I haven't been able to validate that, all attempts to unpack the value end with an 'unexpected EOF' can you show some example code that validates that? Also since the docs say (unix|syscall).Sysctl() returns a string, should it either a) do the binary unpacking and actually return a string like it says. b) say in a note, that it can return non string data and it's up to you to figure it out. or c) return an interface{} and allow the user to do type assertions? |
https://play.golang.org/p/6ibnltrMd6
syscall.Sysctl is returning a string. Go strings aren't necessarily Unicode text. I believe this is working as intended. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?and
What operating system and processor architecture are you using (
go env
)?and
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
Using syscall.Sysctl(name string) (value string, err error) to get any string type value works fine, for example, kern.ostype will return "FreeBSD" or "NetBSD", however tyring to read a numerical value breaks, but does not error. such as hw.physmem which should return me (if things were converted properly) something like "2138501120" but instead gives me a 4 char string, with int values of 0 240 118 127, which is pretty clearly invalid. Perhaps syscall.Sysctl() should return an interface{} and let the user worry about type safety.
https://play.golang.org/p/wbc-OZGw-P for a quick freebsd test
https://play.golang.org/p/PcuDNWnvFz for a quick netbsd test
NOTE: I added "kern.ostype" to the netbsd test to show that the issues doesn't happen when reading a value containing characters, only when reading a numerical value.
What did you expect to see?
A (lets say for example) int64 that's been converted to a string, not unprintable characters.
What did you see instead?
Unprintable characters instead of a valid string. see below for the output of the NetBSD test:
The text was updated successfully, but these errors were encountered: