[#8815] Segfault in libc strlen, via rb_str_new2 — "Sean E. Russell" <ser@...>

Howdy,

12 messages 2006/09/09
[#8817] Re: Segfault in libc strlen, via rb_str_new2 — Eric Hodel <drbrain@...7.net> 2006/09/09

On Sep 8, 2006, at 10:10 PM, Sean E. Russell wrote:

Re: Segfault in libc strlen, via rb_str_new2

From: Eric Hodel <drbrain@...7.net>
Date: 2006-09-09 05:42:02 UTC
List: ruby-core #8817
On Sep 8, 2006, at 10:10 PM, Sean E. Russell wrote:

> Howdy,
>
> Could someone either
>
> a) point me to the known bug report for this, or
> b) try this to confirm that it also segfalts on them
>
> I didn't see a bug report in the tracker, but that doesn't mean one  
> isn't
> there.
>
> This is Ruby 1.8.5 on Linux.  I get a segfault in libc's strlen().
>
> Thanks.
>
> === CODE
> # Create tst.xml:
> #   echo "<a x='1'/>" > tst.xml
> #
> # Run this:
> #   ruby tst.rb tst.xml
> require 'dl/import'
>
> libxml = DL.dlopen( 'libxml2.so' )
> file_reader = libxml[ 'xmlNewTextReaderFilename', 'IS' ]

The documentation says:
xmlTextReaderPtr	xmlNewTextReaderFilename	(const char * URI)

So I think IS is wrong, and PS is correct.

> free_reader = libxml[ 'xmlFreeTextReader', '0I' ]
> pull = libxml[ 'xmlTextReaderRead', 'II' ]
> name = libxml[ 'xmlTextReaderName', 'SI' ]
> has_attributes = libxml[ 'xmlTextReaderHasAttributes', 'SI' ]

The documentation says:
int	xmlTextReaderHasAttributes	(xmlTextReaderPtr reader)

So I think SI is wrong and SP is correct.

> reader = file_reader.call( ARGV[0] )[0]
>
> puts pull.call( reader )[0]
> puts "Name = #{name.call(reader)[0]}"
> has_attributes.call(reader)
>
> free_reader.call(reader)

Looking in gdb, the call is returning 1, not a string, which matches  
up with the documentation.

This program works:

$ cat xml2.rb
require 'dl/import'

libxml = DL.dlopen 'libxml2.dylib'
file_reader = libxml['xmlNewTextReaderFilename', 'PS']
free_reader = libxml['xmlFreeTextReader', '0P']
pull = libxml['xmlTextReaderRead', 'IP']
name = libxml['xmlTextReaderName', 'SP']
has_attributes = libxml['xmlTextReaderHasAttributes', 'IP']

reader = file_reader.call(ARGV[0])[0]

puts pull.call(reader)[0]
puts "Name = #{name.call(reader)[0]}"
puts "has attributes (1, 0, -1)? #{has_attributes.call reader}"

free_reader.call reader
$ ruby xml2.rb tst.xml
1
Name = a
has attributes (1, 0, -1)? 1

-- 
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com



In This Thread