Bugs: Browse | Submit New | Admin

[#26937] read_timeout=() causes segmentation fault

Date:
2009-08-18 03:35
Priority:
3
Submitted By:
Kentaro Fukuchi (kentarofukuchi)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
read_timeout=() causes segmentation fault

Detailed description
Ubuntu 9.04 on x86_64
ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
ruby-serialport 0.7 via rubygems

Ruby-serial port caused a segmentation fault when #read_timeout= was called.
Example:
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'serialport'
=> true
irb(main):003:0> sp = SerialPort.new("/dev/ttyUSB0", 9600)
=> #<SerialPort:0x7f9641de1910>
irb(main):004:0> sp.read_timeout = 100
(irb):5: [BUG] Segmentation fault
ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]

When I attached gdb, following call trace was shown.
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f43b5b596f0 (LWP 484)]
0x00007f43b56b8f40 in rb_io_taint_check () from /usr/lib/libruby1.8.so.1.8
(gdb) bt
#0  0x00007f43b56b8f40 in rb_io_taint_check () from /usr/lib/libruby1.8.so.1.8
#1  0x00007f43b2da9a76 in get_fd_helper (obj=18446744072429324056)
    at impl/posix_serialport.c:43
#2  0x00007f43b2da9c62 in sp_set_read_timeout (self=-1280227560, 
    val=<value optimized out>) at impl/posix_serialport.c:490
#3  0x00007f43b569ac40 in ?? () from /usr/lib/libruby1.8.so.1.8
#4  0x00007f43b569adfa in ?? () from /usr/lib/libruby1.8.so.1.8

Add A Comment: Notepad

Please login


Followup

Message
Date: 2010-02-08 16:38
Sender: Ryan Payne

I concur with Tim regarding the status of this project. It appears
that most of the Rubyforge projects are being phased out and
GemCutter is the new gem repo. I worked with hparra to integrate
the fixes that I made into his fork of serial port. Also, you
no longer have to add gemcutter.org to your gem sources as the
gems.rubyforge.org address is automagically forwarded to
gemcutter.
Date: 2010-02-08 16:13
Sender: Tim Becker

In case anyone else is having this problem:

This project is/seems to be/may be more or less abandoned. 

There is a fork(?) of serialport at github
(http://github.com/hparra/ruby-serialport/) which may be installed
via gemcutter (gem sources -a http://gemcutter.org; gem install
serialport). This contains the necessary fixes.

I can't tell whether the Rubyforge project is abandoned or not,
anyway, the github/gemcutter gem works fine with no need for
patching.
Date: 2010-02-08 15:59
Sender: Tim Becker

Ryan basically described it. As stated below, this also affects
OSX, which is the only plattform I tested on. Patch:

=================================================================
==
--- ext/serialport.c    (revision 79)
+++ ext/serialport.c    (working copy)
@@ -%ld,%ld +%ld,%ld @@
  * Set the state (0 or 1) of the DTR line
  */
 static VALUE sp_set_dtr(self, val)
+   VALUE self, val;
 {
    return sp_set_dtr_impl(self, val);
 }
@@ -%ld,%ld +%ld,%ld @@
  *  supported.
  */
 static VALUE sp_set_flow_control(self, val)
+   VALUE self, val;
 {
    return sp_set_flow_control_impl(self, val);
 }
@@ -%ld,%ld +%ld,%ld @@
  * Note: Read timeouts don't mix well with multi-threading.
  */
 static VALUE sp_set_read_timeout(self, val)
+   VALUE self, val;
 {
    return sp_set_read_timeout_impl(self, val);
 }
@@ -%ld,%ld +%ld,%ld @@
  * Set the state (0 or 1) of the RTS line
  */
 static VALUE sp_set_rts(self, val)
+   VALUE self, val;
 {
    return sp_set_rts_impl(self, val);
 }
@@ -%ld,%ld +%ld,%ld @@
  * Note: Under Posix, write timeouts are not implemented.
  */
 static VALUE sp_set_write_timeout(self, val)
+   VALUE self, val;
 {
    return sp_set_write_timeout_impl(self, val);
 }

Date: 2010-01-02 02:41
Sender: Ryan Payne

OK. Fixed it. The problem is in serialport.c. The arguments to
the sp_set_dt, sp_set_flow_control, sp_set_read_timeout,  sp_set_rts
and sp_set_write_timeout methods were not being defined as VALUEs.
I'll be submitting the patch here in a few minutes.
Date: 2010-01-02 02:08
Sender: Ryan Payne

The following all cause the same seg fault:
flow_control=
read_timeout=
rts=
dtr=

I am trying to debug this and I'll keep you all posted if I get
it figured out.
Date: 2010-01-01 06:52
Sender: Ryan Payne

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000001512641
0x000000010003ea8e in rb_io_taint_check ()
(gdb) bt
#0  0x000000010003ea8e in rb_io_taint_check ()
#1  0x00000001001ad0a0 in get_fd_helper (obj=<value temporarily
unavailable, due to optimizations>) at posix_serialport.c:47
#2  0x00000001001ad553 in sp_set_read_timeout_impl [inlined]
() at /Library/Ruby/Gems/1.8/gems/ruby-serialport-0.7.1/ext/impl/
posix_serialport.c:510
#3  0x00000001001ad553 in sp_set_read_timeout (self=22095424,
val=<value temporarily unavailable, due to optimizations>)
at posix_serialport.c:157
#4  0x00000001000254d5 in rb_proc_call ()
#5  0x0000000100026297 in rb_proc_call ()
#6  0x0000000100020f15 in rb_provided ()
#7  0x00000001000311a9 in rb_eval_string ()
#8  0x00000001000311e3 in ruby_exec ()
#9  0x0000000100031205 in ruby_run ()
#10 0x0000000100000ef0 in main ()

Note: I am running the latest code out of SVN, which includes
the #ifdefs for Ruby 1.9
Date: 2010-01-01 06:24
Sender: Ryan Payne

Pretty much any of the setters (rts=, dts=, read_timeout=) seem
to have this same issue.
Date: 2010-01-01 05:46
Sender: Ryan Payne

I am also getting the same crash on OS X 10.6.2, also x86_64.
Date: 2009-11-11 07:39
Sender: Nick Wimpney

irb
>> require 'serialport'
=> true
>> sp = SerialPort.new("/dev/ttyUSB0", 9600)
=> #<SerialPort:0x7f442bb24a78>
>> sp.read_timeout = 100
(irb):3: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]
Date: 2009-11-11 07:34
Sender: Nick Wimpney

I get the same crash.

I was working with this same module today on my work computer
and it works fine there.  Possibly only a problem on x86_64?

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item