Project

General

Profile

Actions

Backport #6127

closed

IO#ioctl range error in 1.9.3

Added by dlampa (Donovan Lampa) over 12 years ago. Updated about 12 years ago.

Status:
Closed
[ruby-core:43152]

Description

In 32-bit implementations of 1.9.3 passing an (apparently) unsigned value (BIOCIMMEDIATE = 0x80044270) to ioctl throws range error:

ruby-1.9.3-p125 :001 > a,b = IO.pipe
=> [#<IO:fd 5>, #<IO:fd 6>]
ruby-1.9.3-p125 :002 > a.ioctl(0x80044270, "\x01")
RangeError: bignum too big to convert into long' from (irb):2:in ioctl'
from (irb):2
from /Users/dlampa/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `'
ruby-1.9.3-p125 :001 > 0x80044270.class
=> Bignum

When in 32-bit 1.9.1 and 1.9.2 it does not:

ruby-1.9.1-p243 :001 > a,b = IO.pipe
=> [#IO:0x202fefc, #IO:0x202fec4]
ruby-1.9.1-p243 :002 > a.ioctl(0x80044270, "\x01")
Errno::ENOTTY: Inappropriate ioctl for device
from (irb):2:in ioctl' from (irb):2 from /Users/dlampa/.rvm/rubies/ruby-1.9.1-p243/bin/irb:16:in '
ruby-1.9.1-p243 :001 > 0x80044270.class
=> Bignum

OS is [x86_64-darwin10.8.0] however ruby was compiled as 32-bit through rvm using:
rvm_archflags="-arch i386" CFLAGS="-arch i386" LDFLAGS="-arch i386" rvm install [ruby-version] --patch osx-arch-fix

The patch is installed in ~/.rvm/patches/ruby/1.9.3/ and is as follows:

--- a/Makefile.in 2010-11-11 15:54:26.000000000 -0600
+++ b/Makefile.in 2010-11-11 15:55:24.000000000 -0600
@@ -55,7 +55,7 @@ XLDFLAGS = @XLDFLAGS@ $(EXTLDFLAGS)
EXTLIBS =
LIBS = @LIBS@ $(EXTLIBS)
MISSING = @LIBOBJS@ @ALLOCA@
-LDSHARED = @LIBRUBY_LDSHARED@
+LDSHARED = @LIBRUBY_LDSHARED@ $(LDFLAGS)
DLDFLAGS = @LIBRUBY_DLDFLAGS@ $(EXTLDFLAGS) @ARCH_FLAG@
SOLIBS = @SOLIBS@
MAINLIBS = @MAINLIBS@

this issue appears to be related (http://bugs.ruby-lang.org/issues/5429), but I don't speak Japanese.


Files

ruby-io-c.patch (10.3 KB) ruby-io-c.patch dlampa (Donovan Lampa), 10/10/2012 11:20 PM

Related issues 2 (0 open2 closed)

Related to Ruby master - Bug #5429: 64ビットなFreeBSDのioctlでビット31が1なリクエストの時の不具合Closedmetanest (Makoto Kishimoto)10/10/2011Actions
Has duplicate Ruby master - Bug #7144: [mingw] 1.9.3 backport r37138 breaks buildClosednaruse (Yui NARUSE)10/12/2012Actions

Updated by ko1 (Koichi Sasada) over 12 years ago

  • Assignee set to naruse (Yui NARUSE)
Actions #2

Updated by nobu (Nobuyoshi Nakada) over 12 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby master to Backport193

Updated by naruse (Yui NARUSE) over 12 years ago

This is fixed on trunk with commits 33711,33713,33714,33715,33716,33717,33718,33719,33720,33721,33724,33727,33728,33752,33753.
But can't apply as is.
Anyone can apply it?

Updated by dlampa (Donovan Lampa) over 12 years ago

Any updates on this? Has it been applied or is there a scheduled date for application?

Updated by naruse (Yui NARUSE) over 12 years ago

  • Status changed from Open to Feedback

Updated by dlampa (Donovan Lampa) over 12 years ago

Apologies for the hiatus also apologies if I've misunderstood the meaning of the Feedback status.

1.9.3-p194 doesn't seem to have addressed this:

ruby-1.9.3-p194 :002 > a,b = IO.pipe
=> [#<IO:fd 5>, #<IO:fd 6>]
ruby-1.9.3-p194 :003 > a.ioctl(0x80044270, "\x01")
RangeError: bignum too big to convert into long' from (irb):3:in ioctl'
from (irb):3
from /Users/dlampa/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `'
ruby-1.9.3-p194 :003 > 0x80044270.class
=> Bignum

Updated by naruse (Yui NARUSE) over 12 years ago

dlampa (Donovan Lampa) wrote:

Apologies for the hiatus also apologies if I've misunderstood the meaning of the Feedback status.

In general, "Feedback" means that an action of other than assignee is required.
In this ticket, I need a patch for backport which covers r33711, r33713-r33721, r33724, r33727,
r33728, r33752, and r33753.

Updated by dlampa (Donovan Lampa) about 12 years ago

For those that are interested, I've taken the liberty of putting a patch together for this issue (attached).

The patch is confirmed to work and address the issue as it exists in 1.9.3-p194.

Thanks to Naruse for providing all the relevant commits for this issue.

Actions #9

Updated by naruse (Yui NARUSE) about 12 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r37138.
Donovan, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 33711,33713,33714,33715,33716,33717,33718,33719,33720,33721,33724,33727,33728,33752,33753: [Backport #6127]

    * io.c (ioctl_req_t): Type of req argument of ioctl() depend on platform.
      Moreover almost all linux ioctl can't be represented by 32bit integer
      (i.e. MSB is 1). We need wrap ioctl argument type.
    [Bug #5429] [ruby-dev:44589]
    * io.c (struct ioctl_arg): ditto.
    * io.c (rb_ioctl): ditto.
    * test/ruby/test_io.rb (test_ioctl_linux): add a testcase for ioctl
    * backporting patch is created by Donovan Lampa.

Updated by h.shirosaki (Hiroshi Shirosaki) about 12 years ago

I have a build error of ruby_1_9_3 branch at r37146 with mingw.
It seems due to r37138.

compiling ../io.c
../io.c: In function 'rb_cloexec_fcntl_dupfd':
../io.c:213:21: error: 'F_DUPFD' undeclared (first use in this function)
../io.c:213:21: note: each undeclared identifier is reported only once for each function it appears in
../io.c: In function 'rb_io_each_byte':
../io.c:3081:15: warning: variable 'e' set but not used [-Wunused-but-set-variable]
../io.c: In function 'rb_io_advise':
../io.c:7892:16: warning: variable 'l' set but not used [-Wunused-but-set-variable]
../io.c:7892:11: warning: variable 'off' set but not used [-Wunused-but-set-variable]
../io.c: At top level:
../io.c:1575:14: warning: 'nogvl_fsync' defined but not used [-Wunused-function]
make: *** [io.o] Error 1

Here is a patch.

Index: io.c

--- io.c (revision 37146)
+++ io.c (working copy)
@@ -209,8 +209,10 @@
else {
ret = fcntl(fd, F_DUPFD, minfd);
}
+#elif defined(F_DUPFD)

  • ret = fcntl(fd, F_DUPFD, minfd);
    #else
  • ret = fcntl(fd, F_DUPFD, minfd);
  • ret = -1;
    #endif
    if (ret == -1) return -1;
    rb_maygvl_fd_fix_cloexec(ret);
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0