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

Use .blank? instead of .empty? when handling SSH Key details to prevent crashes #17416

Merged
merged 1 commit into from
Dec 28, 2022
Merged

Conversation

MegaManSec
Copy link
Contributor

@MegaManSec MegaManSec commented Dec 27, 2022

blank? should be used instead of empty?. When running this script on a host which has a blank SSH key, an error is encountered:

[-] Post failed: NoMethodError undefined method `empty?' for nil:NilClass
[-] Call stack:
[-]   /opt/metasploit-framework/embedded/framework/modules/post/multi/gather/jenkins_gather.rb:235:in `block in pretty_print_gathered'
[-]   /opt/metasploit-framework/embedded/framework/modules/post/multi/gather/jenkins_gather.rb:231:in `each'
[-]   /opt/metasploit-framework/embedded/framework/modules/post/multi/gather/jenkins_gather.rb:231:in `pretty_print_gathered'
[-]   /opt/metasploit-framework/embedded/framework/modules/post/multi/gather/jenkins_gather.rb:348:in `gathernix'
[-]   /opt/metasploit-framework/embedded/framework/modules/post/multi/gather/jenkins_gather.rb:363:in `run'

Comment on lines 234 to 236
print_status(" Description: #{e[1]}") if !e[1].nil? || !e[1].blank?
print_status(" Passphrase: #{e[2]}") if !e[2].nil? || !e[2].blank?
print_status(" Username: #{e[3]}") if !e[3].nil? || !e[3].blank?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.blank? would also check if the object is nil as well and so the first part of this code would not be needed. Might I suggest this instead to simplify the code?

Suggested change
print_status(" Description: #{e[1]}") if !e[1].nil? || !e[1].blank?
print_status(" Passphrase: #{e[2]}") if !e[2].nil? || !e[2].blank?
print_status(" Username: #{e[3]}") if !e[3].nil? || !e[3].blank?
print_status(" Description: #{e[1]}") if !e[1].blank?
print_status(" Passphrase: #{e[2]}") if !e[2].blank?
print_status(" Username: #{e[3]}") if !e[3].blank?

For reference this is what happens with a .blank? call on nil object:

>> nil.blank?
=> true
>> !nil.blank?
=> false
>> 

https://blog.appsignal.com/2018/09/11/differences-between-nil-empty-blank-and-present.html has more details on this if you wish to read up more about this 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with latest updates.

@gwillcox-r7
Copy link
Contributor

Will go ahead and rebase this against the latest code changes on master so that this passes tests. Then will make the changes so this can be landed.

blank? should be used instead of empty?
@gwillcox-r7
Copy link
Contributor

With latest updates this should be good to go, will just wait for tests to pass before landing this.

@gwillcox-r7 gwillcox-r7 self-assigned this Dec 28, 2022
@gwillcox-r7 gwillcox-r7 added module bug rn-fix release notes fix labels Dec 28, 2022
@gwillcox-r7 gwillcox-r7 changed the title Update jenkins_gather.rb Use .blank? instead of .empty? inside of jenkins_gather.rb to fix a Nil crash Dec 28, 2022
@gwillcox-r7 gwillcox-r7 changed the title Use .blank? instead of .empty? inside of jenkins_gather.rb to fix a Nil crash Use .blank? instead of .empty? when handling SSH Key details to prevent crashes Dec 28, 2022
@gwillcox-r7 gwillcox-r7 merged commit 7b25c75 into rapid7:master Dec 28, 2022
@gwillcox-r7
Copy link
Contributor

Release Notes

The jenkins_gather.rb module has been updated to use .blank? instead of .empty? when handling SSH Key details to prevent crashes should the various elements of the SSH Key be empty or nil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug module rn-fix release notes fix
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants