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

solargraph scan crashes when scanning ffi_c's Pointer.c file #634

Open
gwillcox-r7 opened this issue Feb 9, 2023 · 4 comments
Open

solargraph scan crashes when scanning ffi_c's Pointer.c file #634

gwillcox-r7 opened this issue Feb 9, 2023 · 4 comments

Comments

@gwillcox-r7
Copy link
Contributor

gwillcox-r7 commented Feb 9, 2023

When running solargraph scan using the latest code from master I end up with the following crash when scanning code:

 ~/git/metasploit-framework │ master ?23  solargraph scan                         ✔ │ 3.0.5 Ruby │ 10:16:34 AM 
[WARN] Yardoc at /home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/doc/aws-sdk-ec2-1.364.0/.yardoc is too large to process (25134849 bytes)
Error testing FFI::Pointer#order (/home/gwillcox/.rbenv/versions/3.0.5/lib/ruby/gems/3.0.0/gems/ffi-1.15.5/ext/ffi_c/Pointer.c 332) at /home/gwillcox/.rbenv/versions/3.0.5/lib/ruby/gems/3.0.0/gems/ffi-1.15.5/ext/ffi_c/Pointer.c:333
[NoMethodError]: undefined method `each_char' for nil:NilClass
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/complex_type.rb:172:in `block in parse'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/complex_type.rb:166:in `each'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/complex_type.rb:166:in `parse'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/complex_type.rb:239:in `try_parse'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/pin/method.rb:178:in `block in overloads'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/pin/method.rb:164:in `map'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/pin/method.rb:164:in `overloads'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/pin/method.rb:58:in `signatures'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/pin/method.rb:49:in `return_type'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/pin/base.rb:144:in `typify'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/pin/method.rb:95:in `typify'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/shell.rb:185:in `block (2 levels) in scan'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/shell.rb:182:in `each'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/shell.rb:182:in `block in scan'
/home/gwillcox/.rbenv/versions/3.0.5/lib/ruby/3.0.0/benchmark.rb:293:in `measure'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/lib/solargraph/shell.rb:180:in `scan'
/home/gwillcox/.rbenv/versions/3.0.5/lib/ruby/gems/3.0.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
/home/gwillcox/.rbenv/versions/3.0.5/lib/ruby/gems/3.0.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
/home/gwillcox/.rbenv/versions/3.0.5/lib/ruby/gems/3.0.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
/home/gwillcox/.rbenv/versions/3.0.5/lib/ruby/gems/3.0.0/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/gems/solargraph-0.49.0/bin/solargraph:5:in `<top (required)>'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/bin/solargraph:25:in `load'
/home/gwillcox/.rbenv/versions/3.0.5/gemsets/metasploit-framework/bin/solargraph:25:in `<main>'

Looks like somehow type_string is becoming an object in the block that does not have the .each_char method associated with that object.

@gwillcox-r7 gwillcox-r7 changed the title Crash on Solargraph master branch When Running solargraph scan solargraph scan crashes when scanning ffi_c's Pointer.c file Feb 9, 2023
@johnhamelink
Copy link

Does anyone know how to skip past this file?

I tried the following exclusion patterns:

exclude:
- "*/**/Pointer.c"
- "ext/ffi_c/Pointer.c"
- "ffi_c/Pointer.c"
- "Pointer.c"

@gastonmorixe
Copy link
Contributor

gastonmorixe commented Aug 12, 2023

This patch should fix it

diff --git a/lib/solargraph/complex_type.rb b/lib/solargraph/complex_type.rb
index 32574ec8..89dfaa6c 100644
--- a/lib/solargraph/complex_type.rb
+++ b/lib/solargraph/complex_type.rb
@@ -169,7 +169,7 @@ module Solargraph
           paren_stack = 0
           base = String.new
           subtype_string = String.new
-          type_string.each_char do |char|
+          type_string&.each_char do |char|
             if char == '='
               #raise ComplexTypeError, "Invalid = in type #{type_string}" unless curly_stack > 0
             elsif char == '<'

gastonmorixe added a commit to rocketreferrals/solargraph that referenced this issue Aug 12, 2023
@4rgc
Copy link

4rgc commented Aug 24, 2023

+1 on this issue!

@metalelf0
Copy link

Upgrading ffi to 1.16.2 fixed this issue for me.

castwide pushed a commit that referenced this issue Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants