Skip to content

Commit

Permalink
Unsafe int cast in kill command (cometbft#783)
Browse files Browse the repository at this point in the history
* Unsafe int cast in `kill` command

* Revert "Unsafe int cast in `kill` command"

This reverts commit bbd649b.

* Changed strategy

(cherry picked from commit 03c5e77)

# Conflicts:
#	cmd/cometbft/commands/debug/kill.go
  • Loading branch information
sergio-mena authored and mergify[bot] committed May 4, 2023
1 parent 38ab766 commit 5cf3226
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cmd/cometbft/commands/debug/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ $ cometbft debug 34255 /path/to/cmt-debug.zip`,
RunE: killCmdHandler,
}

<<<<<<< HEAD
func killCmdHandler(cmd *cobra.Command, args []string) error {
pid, err := strconv.ParseUint(args[0], 10, 64)
=======
func killCmdHandler(_ *cobra.Command, args []string) error {
pid, err := strconv.Atoi(args[0])
>>>>>>> 03c5e7727 (Unsafe int cast in `kill` command (#783))
if err != nil {
return err
}
Expand Down Expand Up @@ -100,7 +105,7 @@ func killCmdHandler(cmd *cobra.Command, args []string) error {
// is tailed and piped to a file under the directory dir. An error is returned
// if the output file cannot be created or the tail command cannot be started.
// An error is not returned if any subsequent syscall fails.
func killProc(pid uint64, dir string) error {
func killProc(pid int, dir string) error {
// pipe STDERR output from tailing the CometBFT process to a file
//
// NOTE: This will only work on UNIX systems.
Expand All @@ -123,7 +128,7 @@ func killProc(pid uint64, dir string) error {
go func() {
// Killing the CometBFT process with the '-ABRT|-6' signal will result in
// a goroutine stacktrace.
p, err := os.FindProcess(int(pid))
p, err := os.FindProcess(pid)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to find PID to kill CometBFT process: %s", err)
} else if err = p.Signal(syscall.SIGABRT); err != nil {
Expand Down

0 comments on commit 5cf3226

Please sign in to comment.