castwide / solargraph

A Ruby language server.
https://solargraph.org
MIT License
1.87k stars 154 forks source link

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

Open gwillcox-r7 opened 1 year ago

gwillcox-r7 commented 1 year ago

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.

johnhamelink commented 1 year ago

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 commented 11 months ago

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 == '<'
4rgc commented 10 months ago

+1 on this issue!

metalelf0 commented 9 months ago

Upgrading ffi to 1.16.2 fixed this issue for me.