Bugs item #10402, was opened at 2007-04-27 01:58
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=10402&group_id=426

Category: Core
Group: 1.8.5
Status: Open
Resolution: None
Priority: 3
Submitted By: Max Power (anansi)
Assigned to: Nobody (None)
Summary: segmentation fault when executing ruby script

Initial Comment:
Hi,
okay I don't actually know if this error is connected to the ruby-core or the lib I use but I think it is in the core because it segfaults. I also mailed the developer of the lib my problem who gave me a sample code but he didn't mailed back until now. So I thought posting here wouldn't be the worst idea.

So here is the script and it's execution output:

anansi@anansi-laptop:~/Desktop$ cat tcpsyn.rb
require 'libnet'   # needs ruby-libnet installed

l = Libnet.new

10.times do
   l.build_tcp(31337, 80, rand(2 ** 3), 0, Libnet::TH_SYN, 0, 0, 0, Libnet::LIBNET_TCP_H, nil, 0, nil)
   l.auto_build_ipv4(Libnet::LIBNET_TCP_H + Libnet::LIBNET_IPV4_H, Libnet::IPPROTO_TCP, "192.168.0.2")
   l.auto_build_ethernet(l.hex_aton("00:11:11:94:D4:F5"), Libnet::ETHERTYPE_IP)
   ret = l.write
   l.clear_packet
   puts l.geterror if ret < 0
end

sent,error,written = l.stats
puts ""
puts "Sent: #{sent}"
puts "Error: #{error}"
puts "Bytes Written: #{written}"

anansi@anansi-laptop:~/Desktop$ sudo ruby tcpsyn.rb
tcpsyn.rb:6: [BUG] Segmentation fault
ruby 1.8.5 (2006-08-25) [i486-linux]

Aborted
anansi@anansi-laptop:~/Desktop$ 


I also did a gdb backtrace and examined stack, registers and pc:


anansi@anansi-laptop:~/Desktop$ sudo gdb `which ruby`
GNU gdb 6.6-debian
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...

warning: not using untrusted file "/home/anansi/.gdbinit"
(no debugging symbols found)
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) b main
Breakpoint 1 at 0x8048640
(gdb) run ./tcpsyn.rb
Starting program: /usr/bin/ruby ./tcpsyn.rb
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
[Thread debugging using libthread_db enabled]
[New Thread -1211266224 (LWP 11035)]
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
[Switching to Thread -1211266224 (LWP 11035)]

Breakpoint 1, 0x08048640 in main ()
(gdb) i r
eax            0xbf9cc1e4       -1080245788
ecx            0xbf9cc160       -1080245920
edx            0x2      2
ebx            0xb7e15ff4       -1209966604
esp            0xbf9cc130       0xbf9cc130
ebp            0xbf9cc148       0xbf9cc148
esi            0xb7f84ce0       -1208464160
edi            0x0      0
eip            0x8048640        0x8048640 <main+16>
eflags         0x286    [ PF SF IF ]
cs             0x73     115
ss             0x7b     123
ds             0x7b     123
es             0x7b     123
fs             0x0      0
gs             0x33     51
(gdb) x/30w $esp
0xbf9cc130:     0xb7e15ff4      0xbf9cc1f0      0xbf9cc158      0xb7e15ff4
0xbf9cc140:     0xb7f787b0      0x08048690      0xbf9cc1b8      0xb7ceeebc
0xbf9cc150:     0xb7f84ce0      0x08048690      0xbf9cc1b8      0xb7ceeebc
0xbf9cc160:     0x00000002      0xbf9cc1e4      0xbf9cc1f0      0xb7f85898
0xbf9cc170:     0x00000000      0x00000001      0x00000001      0x00000000
0xbf9cc180:     0xb7e15ff4      0xb7f84ce0      0x00000000      0xbf9cc1b8
0xbf9cc190:     0x4096c160      0x48c4ee81      0x00000000      0x00000000
0xbf9cc1a0:     0x00000000      0xb7f7d300
(gdb) set disassembly-flavor intel
(gdb) x /6i $pc
0x8048640 <main+16>:    mov    DWORD PTR [ebp-12],ebx
0x8048643 <main+19>:    call   0x8048672
0x8048648 <main+24>:    add    ebx,0x1218
0x804864e <main+30>:    mov    DWORD PTR [ebp-16],ecx
0x8048651 <main+33>:    mov    DWORD PTR [ebp-4],edi
0x8048654 <main+36>:    mov    edi,DWORD PTR [ecx]
(gdb) n
Single stepping until exit from function main,
which has no line number information.

Program received signal SIGSEGV, Segmentation fault.
0xb7d40930 in ?? () from /lib/tls/i686/cmov/libc.so.6
(gdb) bt
#0  0xb7d40930 in ?? () from /lib/tls/i686/cmov/libc.so.6
#1  0x00000001 in ?? ()
#2  0x00000104 in ?? ()
#3  0x00000000 in ?? ()
(gdb)


Can someone confirm this error as ruby bug?

greets

----------------------------------------------------------------------

Comment By: Daniel Berger (djberg96)
Date: 2007-04-27 08:44

Message:
I doubt this is a bug in Ruby. The ruby-libnet package is a C extension, which means the culprit is almost certainly in the ruby-libnet code itself, not Ruby.

Given that the ruby-libnet package is pre-alpha, with no official file releases, bugs like this should come as no surprise.

I recommend posting this bug on the ruby-libnet project page.

Regards,

Dan

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=10402&group_id=426