From 1354dd4fd0ddb23ada9fa8596ab6411142b45d7f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 29 Dec 2025 08:12:40 +0000 Subject: [PATCH] Security fix: Handle errors in pr_command.go cleanup operations (Alerts #403-404) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed unhandled errors from os.RemoveAll() at lines 636 and 645. Added proper error handling that logs warnings when cleanup fails. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- pkg/cli/pr_command.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/cli/pr_command.go b/pkg/cli/pr_command.go index be579c91f74..b730b9b9831 100644 --- a/pkg/cli/pr_command.go +++ b/pkg/cli/pr_command.go @@ -633,7 +633,10 @@ func transferPR(prURL, targetRepo string, verbose bool) error { cloneCmd := workflow.ExecGH("repo", "clone", fmt.Sprintf("%s/%s", targetOwner, targetRepoName), tempDir) if err := cloneCmd.Run(); err != nil { - os.RemoveAll(tempDir) + // Clean up temporary directory on error + if rmErr := os.RemoveAll(tempDir); rmErr != nil && verbose { + fmt.Fprintf(os.Stderr, "Warning: failed to clean up temporary directory %s: %v\n", tempDir, rmErr) + } return fmt.Errorf("failed to clone target repository: %w", err) } @@ -642,7 +645,10 @@ func transferPR(prURL, targetRepo string, verbose bool) error { // Change to the cloned repository directory if err := os.Chdir(tempDir); err != nil { - os.RemoveAll(tempDir) + // Clean up temporary directory on error + if rmErr := os.RemoveAll(tempDir); rmErr != nil && verbose { + fmt.Fprintf(os.Stderr, "Warning: failed to clean up temporary directory %s: %v\n", tempDir, rmErr) + } return fmt.Errorf("failed to change to cloned repository directory: %w", err) } }