Skip to content
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

syscall: add validation syscall.Kill #9935

Closed
eranb opened this issue Feb 19, 2015 · 3 comments
Closed

syscall: add validation syscall.Kill #9935

eranb opened this issue Feb 19, 2015 · 3 comments

Comments

@eranb
Copy link

eranb commented Feb 19, 2015

I don't know if you can validate stuff before sending "invalid" system calls, but the code below cause the Kernel to terminate the program, it could be nice if go could throw panic in these situations, it will be much easier to debug, I had to use strace to figure it out.

version: go version go1.4.1 darwin/amd64 ( installed via the official package for os x )
os: OS X 10.10.1 - Yosemite

package main

import (
    "strconv"
    "syscall"
)

func main() {
    pid, _ := strconv.Atoi("")
    syscall.Kill(pid, syscall.SIGKILL)
}
@adg adg changed the title Add validation syscall.Kill syscall: add validation syscall.Kill Feb 19, 2015
@adg
Copy link
Contributor

adg commented Feb 19, 2015

The first step in debugging a Go program is to check your errors. Checking the result of strconv.Atoi would have been easier than using strace.

I don't think we can sensibly guard against sending bad arguments to system calls. There are so many system calls, and different kernels regard different inputs as valid and invalid. The programmer should take care when making system calls.

I'm going to close this issue, but someone can re-open it if they feel differently.

@adg adg closed this as completed Feb 19, 2015
@eranb
Copy link
Author

eranb commented Feb 19, 2015

@adg cool so thanks for your help and your quick response

@minux
Copy link
Member

minux commented Feb 20, 2015

The problem is that 0 is a valid pid argument to syscall.Kill, and
it means send the signal to the current process group.

Even if we want to validate the arguments, we can't panic in that
case.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants