Skip to content

Fix frozen string error in FTP mixin when using frozen_string_literal: true#21658

Open
lxcxjxhx wants to merge 2 commits into
rapid7:masterfrom
lxcxjxhx:fix-frozen-string-ftp-mixin-21597
Open

Fix frozen string error in FTP mixin when using frozen_string_literal: true#21658
lxcxjxhx wants to merge 2 commits into
rapid7:masterfrom
lxcxjxhx:fix-frozen-string-ftp-mixin-21597

Conversation

@lxcxjxhx

@lxcxjxhx lxcxjxhx commented Jul 8, 2026

Copy link
Copy Markdown

Motivation

Fixes #21597

The recv_ftp_resp method in Exploit::Remote::Ftp mixin modifies @ftpbuff string 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, causing FrozenError when attempting to modify it.

Changes

Modified lib/msf/core/exploit/remote/ftp.rb:

Before:

@ftpbuff = ''

After:

@ftpbuff = +''

The unary plus operator (+) creates an unfrozen mutable string, ensuring compatibility with frozen_string_literal: true pragma.

Testing

Added test file test/modules/test_ftp_frozen_string.rb with:

  • Test verifying @ftpbuff is mutable even with frozen_string_literal: true
  • Test verifying recv_ftp_resp works correctly without raising FrozenError
  • Tested with auxiliary/dos/ftp/vsftpd_232.rb using frozen_string_literal: true
  • Verified with vsftpd 3.0.2 docker container

Impact

  • Allows modules to safely use frozen_string_literal: true pragma as required by AGENTS.md
  • Maintains backward compatibility with existing modules
  • No breaking changes to API or behavior

Checklist

lxcxjxhx added 2 commits July 8, 2026 12:57
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Modifying a frozen string cause an error in Exploit::Remote::Ftp mixin

2 participants