Skip to content

[BeEF] Fix bare 'rescue' in spec_helper.rb#3558

Open
mitre88 wants to merge 2 commits intobeefproject:masterfrom
mitre88:fix/bare-rescue-spec-helper
Open

[BeEF] Fix bare 'rescue' in spec_helper.rb#3558
mitre88 wants to merge 2 commits intobeefproject:masterfrom
mitre88:fix/bare-rescue-spec-helper

Conversation

@mitre88
Copy link
Copy Markdown

@mitre88 mitre88 commented May 1, 2026

Summary

Fixes a bare rescue clause in spec/spec_helper.rb that catches all exceptions including system-exiting ones.

Issue

The code at line 170 used a bare rescue:

begin
  Process.kill('KILL', pid) if pid
rescue
  # ignore
end

Bare rescue is equivalent to rescue StandardError in Ruby 2.x+, but still catches StandardError and its subclasses. This should only catch expected errors (like Errno::ESRCH when the process doesn't exist), not system-level exceptions like:

  • NoMemoryError
  • SecurityError
  • SystemExit

Fix

Changed to rescue StandardError which is more explicit and documented intent. This still catches all expected errors while being intentional about what's being caught.

Open Source Contributor added 2 commits April 30, 2026 20:08
- Wrap File.open in a context manager (block) instead of storing
  the file handle in a local variable
- Move function definition and main logic inside the block to
  ensure proper cleanup
- Fix potential file descriptor leak if an exception occurred
  before log_file.close was called
Replace bare 'rescue' with 'rescue StandardError' to avoid
catching unexpected system-wide exceptions like NoMemoryError,
SystemExit, and SecurityError. This is safer for cleanup code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant