Fix frozen string error in FTP mixin when using frozen_string_literal: true#21658
Open
lxcxjxhx wants to merge 2 commits into
Open
Fix frozen string error in FTP mixin when using frozen_string_literal: true#21658lxcxjxhx wants to merge 2 commits into
lxcxjxhx wants to merge 2 commits into
Conversation
Fixes rapid7#21597 The recv_ftp_resp method in Exploit::Remote::Ftp mixin modifies @ftpbuff by appending data with << operator. When modules use frozen_string_literal: true (as now required by AGENTS.md), the string literal '' becomes frozen, causing FrozenError when attempting to modify it. This fix initializes @ftpbuff with +'' (unary plus) to create an unfrozen mutable string, ensuring compatibility with frozen_string_literal: true. Changes: - Changed @ftpbuff = '' to @ftpbuff = +'' in initialize method - Allows modules to safely use frozen_string_literal: true pragma - Maintains backward compatibility with existing modules Testing: - Verified with auxiliary/dos/ftp/vsftpd_232.rb using frozen_string_literal: true - Confirmed recv_ftp_resp no longer raises FrozenError - Tested with vsftpd 3.0.2 docker container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Fixes #21597
The
recv_ftp_respmethod inExploit::Remote::Ftpmixin modifies@ftpbuffstring by appending data with<<operator. When modules use# frozen_string_literal: true(as now required by AGENTS.md for new files), the string literal''becomes frozen, causingFrozenErrorwhen attempting to modify it.Changes
Modified
lib/msf/core/exploit/remote/ftp.rb:Before:
After:
The unary plus operator (
+) creates an unfrozen mutable string, ensuring compatibility withfrozen_string_literal: truepragma.Testing
Added test file
test/modules/test_ftp_frozen_string.rbwith:@ftpbuffis mutable even withfrozen_string_literal: truerecv_ftp_respworks correctly without raisingFrozenErrorauxiliary/dos/ftp/vsftpd_232.rbusingfrozen_string_literal: trueImpact
frozen_string_literal: truepragma as required by AGENTS.mdChecklist
Exploit::Remote::Ftpmixin #21597