Fix FileStat stat parsing on non-GNU systems#20830
Fix FileStat stat parsing on non-GNU systems#20830cdelafuente-r7 merged 1 commit intorapid7:masterfrom
Conversation
cdelafuente-r7
left a comment
There was a problem hiding this comment.
Thanks @SilentSobs for fixing this. I just left a minor suggestion before it lands. I tested against FreeBSD v14.3 and the new stat format works.
| ).to_s.chomp | ||
| end | ||
|
|
||
| raise 'format argument of stat command not behaving as expected' unless data =~ /(\d+,){12}\w+/ |
There was a problem hiding this comment.
There is another problem that was highlighted in the original issue. This line is likely the cause of this.
Even if the format is good, the call can still return an error, for example, if the file doesn't exist. The current error message is confusing since it refers to the format arguments. I would suggest to change this error message and give more feedback to the user:
| raise 'format argument of stat command not behaving as expected' unless data =~ /(\d+,){12}\w+/ | |
| raise "stat command returned an unexpected result: #{data}" unless data =~ /(\d+,){12}\w+/ |
|
Hello! I'm wondering if you have any updates on this. I would be happy to help if you have questions or blockers. |
|
Sorry I making a update .. give me hour |
0a4d6c7 to
b6d1b7c
Compare
|
I'm looking to contribute more to Metasploit. Are there any open issues or areas where a bigger contribution would be helpful? I'm comfortable with Ruby, post modules, and security research |
|
Thanks for updating this @SilentSobs ! Everything looks good to me now. I tested against FreeBSD v14.3 and verified the That's a great news! I will be happy to help you for any contribution to Metasploit. We can have this discussion on the public Metasploit Slack. Look for |
Release NotesThis fixes a portability issue in |
This PR fixes a portability issue in Msf::Post::File.stat where the implementation assumed GNU stat --format output.
On non-GNU systems (such as BSD variants), the existing code raised a runtime exception because the stat output did not match the expected format. This change preserves existing GNU/Linux behavior and adds a minimal, behavior-based fallback to a BSD-compatible stat -f format when the initial output does not match expectations.
No OS detection is introduced, and no external interfaces are changed.
Fixes #20030