From 9b535414632d2d01c9a6808d55a12bb51bcb23b9 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 4 May 2023 19:59:09 +0200 Subject: [PATCH] Unsafe int cast in `kill` command (backport #783) (#793) * Unsafe int cast in `kill` command (#783) * Unsafe int cast in `kill` command * Revert "Unsafe int cast in `kill` command" This reverts commit bbd649bd372ca90f83dea7b424d67dafbd9eb541. * Changed strategy (cherry picked from commit 03c5e7727a03983b54623e731d5d3d8dd4ac75ec) # Conflicts: # cmd/cometbft/commands/debug/kill.go * Revert "Unsafe int cast in `kill` command (#783)" This reverts commit 5cf3226cee122f197ec928daaf67864306196d32. * Unsafe int cast in `kill` command (#783) * Unsafe int cast in `kill` command * Revert "Unsafe int cast in `kill` command" This reverts commit bbd649bd372ca90f83dea7b424d67dafbd9eb541. * Changed strategy --------- Co-authored-by: Sergio Mena --- cmd/cometbft/commands/debug/kill.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/cometbft/commands/debug/kill.go b/cmd/cometbft/commands/debug/kill.go index 3a1c993bcdc..93edde582e9 100644 --- a/cmd/cometbft/commands/debug/kill.go +++ b/cmd/cometbft/commands/debug/kill.go @@ -33,7 +33,7 @@ $ cometbft debug 34255 /path/to/cmt-debug.zip`, } func killCmdHandler(cmd *cobra.Command, args []string) error { - pid, err := strconv.ParseUint(args[0], 10, 64) + pid, err := strconv.Atoi(args[0]) if err != nil { return err } @@ -100,7 +100,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. @@ -123,7 +123,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 {