Hi kcc,

Thanks for your hint. It did get me further to some point.

I successfully compiled Ruby, libxml2, libxst and Nokogiri  with ASan, but 
when I run it I still get:

    ./ruby ../script.rb
    Traceback (most recent call last):
        7: from ../script.rb:1:in `<main>'
        6: from 
/usr/local/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in 
`require'
        5: from 
/usr/local/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in 
`rescue in require'
        4: from 
/usr/local/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in 
`require'
        3: from 
/usr/local/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.0/lib/nokogiri.rb:28:in 
`<top (required)>'
        2: from 
/usr/local/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.0/lib/nokogiri.rb:32:in 
`rescue in <top (required)>'
        1: from 
/usr/local/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in 
`require'
    /usr/local/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in 
`require': /usr/local/lib/libxml2.so.2: undefined symbol: __asan_init - 
/usr/local/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.0/lib/nokogiri/nokogiri.so 
(LoadError)

Any ideas?

Any body with Ruby experience and enabling ASan for Ruby Gems?

Thanks,

On Friday, May 18, 2018 at 10:16:00 PM UTC+2, kcc wrote:
>
> I have zero experience with Ruby, but if it is any similar to Python then 
> my recommendation is to build Ruby with AddressSanitizer. 
> If the build breaks with an LSAN report, just disable LSAN during the 
> build (ASAN_OPTIONS=detect_leaks=0)
>
> --kcc 
>
>
>
> On Fri, May 18, 2018 at 3:15 AM MK <[email protected] <javascript:>> 
> wrote:
>
>> Hi all,
>>
>> I am trying to compile Address Sanitizer in nokogiri Ruby gem.
>>
>> Compiled libxml2 and libxslt with Address Sanitizer like this:
>>
>> ./configure CFLAGS="-fsanitize=address,undefined -Wformat 
>> -Werror=format-security -Werror=array-bounds -g" 
>> CXXFLAGS="-fsanitize=address,undefined -Wformat -Werror=format-security 
>> -Werror=array-bounds -g" LDFLAGS="-fsanitize=address,undefined" CC="clang" 
>> CXX="clang++"
>>
>>
>> And installed gem like this:
>>
>> sudo gem install nokogiri --version 1.8.0 -- --use-system-libraries 
>> --with-xml2-include=/home/user/Downloads/libxml2-2.9.3/include/ 
>> --with-xml2-lib=/usr/local/lib/ --with-cflags=\"-fsanitize=address\" 
>> --with-ldflags=\"-fsanitize=address -lasan -lubsan\" 
>> --with-xslt-include=/home/user/Downloads/libxslt-1.1.28/
>>
>>
>> However when I run sample Ruby script using Nokogiri
>>
>> script.rb
>> #!/usr/bin/ruby 
>> require 'nokogiri' 
>> doc = File.open("sample.xml") { |f| Nokogiri::XML(f) }
>>
>>
>> I get this message: 
>>
>> ./script.rb ==30473==ASan runtime does not come first in initial library 
>> list; you should either link runtime to your application or manually 
>> preload it with LD_PRELOAD.
>>
>>
>> When I do the preload: 
>>
>>
>>  LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.2 ./script.rb
>>     /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in 
>> `require': 
>> /var/lib/gems/2.3.0/gems/nokogiri-1.8.0/lib/nokogiri/nokogiri.so: undefined 
>> symbol: __asan_init - 
>> /var/lib/gems/2.3.0/gems/nokogiri-1.8.0/lib/nokogiri/nokogiri.so (LoadError)
>>         from 
>> /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
>>         from 
>> /var/lib/gems/2.3.0/gems/nokogiri-1.8.0/lib/nokogiri.rb:32:in `rescue in 
>> <top (required)>'
>>         from 
>> /var/lib/gems/2.3.0/gems/nokogiri-1.8.0/lib/nokogiri.rb:28:in `<top 
>> (required)>'
>>         from 
>> /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
>>         from 
>> /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in 
>> require'
>>         from 
>> /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
>>         from ./script.rb:2:in `<main>'
>>
>>     =================================================================
>>     ==30485==ERROR: LeakSanitizer: detected memory leaks
>>
>>     Direct leak of 319176 byte(s) in 4259 object(s) allocated from:
>>         #0 0x7fce9ea4579a in __interceptor_calloc 
>> (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x9879a)
>>         #1 0x7fce9e5b4383 in ruby_xcalloc 
>> (/usr/lib/x86_64-linux-gnu/libruby-2.3.so.2.3+0x85383)
>>
>> .
>> .
>> .
>> Do I have to build Ruby also with Address Sanitizer? Which unfortunately 
>> fails ...
>>
>> cd ruby-2.3.0
>> ./configure --disable-shared CFLAGS="-fsanitize=address -ggdb" 
>> CXXFLAGS="-fsanitize=address -ggdb"
>> make
>> Breaks upon compilation, showing Memory Leak :/
>>
>> How do I correctly enable Address Sanitizer in Ruby, on Ruby Gem?
>>
>> Thanks,
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "address-sanitizer" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"address-sanitizer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to