Backport #6127

IO#ioctl range error in 1.9.3

Added by Donovan Lampa about 2 years ago. Updated over 1 year ago.

[ruby-core:43152]
Status:Closed
Priority:Normal
Assignee:Yui NARUSE

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
=> [#, #]
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 [x8664-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 = @LIBRUBYLDSHARED@
+LDSHARED = @LIBRUBY
LDSHARED@ $(LDFLAGS)
DLDFLAGS = @LIBRUBYDLDFLAGS@ $(EXTLDFLAGS) @ARCHFLAG@
SOLIBS = @SOLIBS@
MAINLIBS = @MAINLIBS@

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

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


Related issues

Related to ruby-trunk - Bug #5429: 64ビットなFreeBSDのioctlでビット31が1なリクエストの時の不具合 Closed 10/10/2011
Duplicated by ruby-trunk - Bug #7144: [mingw] 1.9.3 backport r37138 breaks build Closed 10/12/2012

Associated revisions

Revision 37138
Added by Yui NARUSE over 1 year ago

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] 
    * 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.

Revision 37150
Added by Usaku NAKAMURA over 1 year ago

  • io.c (rbcloexecfcntl_dupfd): get rid of compile error on windows. reported by Donovan Lampa at [Backport #6127], based on a patch by Hiroshi Shirosaki at .

History

#1 Updated by Koichi Sasada about 2 years ago

  • Assignee set to Yui NARUSE

#2 Updated by Nobuyoshi Nakada about 2 years ago

  • Tracker changed from Bug to Backport
  • Project changed from ruby-trunk to Backport93

#3 Updated by Yui NARUSE about 2 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?

#4 Updated by Donovan Lampa about 2 years ago

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

#5 Updated by Yui NARUSE about 2 years ago

  • Status changed from Open to Feedback

#6 Updated by Donovan Lampa almost 2 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
=> [#, #]
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

#7 Updated by Yui NARUSE almost 2 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.

#8 Updated by Donovan Lampa over 1 year 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.

#9 Updated by Yui NARUSE over 1 year 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] 
    * 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.

#10 Updated by Hiroshi Shirosaki over 1 year ago

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

compiling ../io.c
../io.c: In function 'rbcloexecfcntldupfd':
../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 'rbioeachbyte':
../io.c:3081:15: warning: variable 'e' set but not used [-Wunused-but-set-variable]
../io.c: In function 'rb
ioadvise':
../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, FDUPFD, minfd);
}
+#elif defined(F
DUPFD)
+ ret = fcntl(fd, FDUPFD, minfd);
#else
- ret = fcntl(fd, F
DUPFD, minfd);
+ ret = -1;
#endif
if (ret == -1) return -1;
rbmaygvlfdfixcloexec(ret);

Also available in: Atom PDF