Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create rubocop rule for preferring File.binread over IO.read #16441

Open
bcoles opened this issue Apr 11, 2022 · 3 comments
Open

Create rubocop rule for preferring File.binread over IO.read #16441

bcoles opened this issue Apr 11, 2022 · 3 comments
Labels
code quality Improving code quality confirmed Issues confirmed by a committer discussion Used on issues/pull requests which have long-lived discussions

Comments

@bcoles bcoles added the code quality Improving code quality label Apr 11, 2022
@adfoster-r7
Copy link
Contributor

For context, we didn't originally add automation for this to the original PR as there are scenarios where IO.read and File.read work just fine, i.e. for wordlists etc, but not for executable binary files.

There are other scenarios where the user's intentions are ambiguous, i.e. if a user uses an ftp upload module - should the bytes be copied verbatim, or should new lines be normalized between the client/target hosts. Other tools solve this by letting the user specify ascii/binary modes, i.e. in the case of bsd's ftp client, or just always uploading in binary mode, i.e. samba's smbclient, but it feels like we'd have to introduce a convention to our modules for that.

It'd be cool to automate this with Rubocop, but I'm on the fence about it solving the underlying issue with above ambiguities. I think the nuances of specifying mode rb or r, or using binread vs readlines vs readlines(chomp: true) may be lost to drive-by contributors, who will just copy/paste from existing modules until rubocop is happy. Although a rule would at least bring an awareness to the issue either way, which is definitely better.

@adfoster-r7
Copy link
Contributor

adfoster-r7 commented Apr 11, 2022

The above aside; msftidy does some checks for specifying binary mode with File.open over here:

url_ok = false if ln =~ /\.com\/projects\/Framework/
if ln =~ /File\.open/ and ln =~ /[\"\'][arw]/
if not ln =~ /[\"\'][wra]\+?b\+?[\"\']/
warn("File.open without binary mode", idx)
end
end

A dedicated rubocop rule will definitely be smarter than this regex 👍

@github-actions
Copy link

Hi!

This issue has been left open with no activity for a while now.

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 30 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request.

@github-actions github-actions bot added the Stale Marks an issue as stale, to be closed if no action is taken label May 12, 2022
@adfoster-r7 adfoster-r7 added discussion Used on issues/pull requests which have long-lived discussions confirmed Issues confirmed by a committer and removed Stale Marks an issue as stale, to be closed if no action is taken labels May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Improving code quality confirmed Issues confirmed by a committer discussion Used on issues/pull requests which have long-lived discussions
Projects
None yet
Development

No branches or pull requests

2 participants