[#47562] [Backport 200 - Backport #8716][Open] segmation fault 正規表現で大量のグループを利用時 — "taka-yoshi (taka-yoshi taka)" <smokeonthewater222@...>

15 messages 2013/08/01

[#47569] [ruby-trunk - Feature #8726][Open] Class#source_location — "takiuchi (Genki Takiuchi)" <genki@...21g.com>

14 messages 2013/08/03

[ruby-dev:47608] Re: [ruby-changes:30446] naruse:r42525 (trunk): * ext/readline/readline.c (readline_s_set_input): on OS X with editline,

From: Tanaka Akira <akr@...>
Date: 2013-08-11 23:48:56 UTC
List: ruby-dev #47608
> naruse  2013-08-12 02:58:07 +0900 (Mon, 12 Aug 2013)
>
>   New Revision: 42525
>
>   http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42525
>
>   Log:
>     * ext/readline/readline.c (readline_s_set_input): on OS X with editline,
>       Readline.readline doesn't work because readline_get doesn't use
>       rl_getc. The difference is introduced by r42402 [ruby-dev:47509]
>       [Bug #8644]. Before it rb_io_stdio_file set ifp->stdio_file.
>       Therefore add manually setting the value.
>
>     * ext/readline/readline.c (readline_s_set_onput): ditto.

readline 側で作った FILE 構造体を ifp->stdio_file にセットすると、
IO#close が fclose を呼んで解放されてしまい、
解放された領域にアクセスしてしまう可能性がありませんか。

とりあえず、以下のようにすると SEGV になりました。

% ./ruby -v -rreadline -e '
r, w = IO.pipe
Readline.input = r
Readline.output = w
r.close
Readline.readline rescue p $!
r, w = IO.pipe
Readline.input = r
Readline.output = w
'
ruby 2.1.0dev (2013-08-12 trunk 42526) [x86_64-linux]
#<IOError: closed stream>
-e:8: [BUG] Segmentation fault
ruby 2.1.0dev (2013-08-12 trunk 42526) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0003 p:---- s:0010 e:000009 CFUNC  :input=
c:0002 p:0097 s:0006 E:001238 EVAL   -e:8 [FINISH]
c:0001 p:0000 s:0002 E:000d28 TOP    [FINISH]

-e:8:in `<main>'
-e:8:in `input='

-- C level backtrace information -------------------------------------------
./ruby(+0x1717a7) [0x7f41d16e17a7]
./ruby(+0x17187c) [0x7f41d16e187c]
./ruby(+0x1caeb4) [0x7f41d173aeb4]
./ruby(rb_bug+0xdf) [0x7f41d173afc9]
./ruby(+0xe966e) [0x7f41d165966e]
/lib/x86_64-linux-gnu/libpthread.so.0(+0xf030) [0x7f41d1141030]
../nptl/sysdeps/pthread/funlockfile.c:30
/lib/x86_64-linux-gnu/libc.so.6(_IO_un_link+0x9e) [0x7f41d05571fe] genops.c:72
/lib/x86_64-linux-gnu/libc.so.6(fclose+0x18d) [0x7f41d054ad0d] iofclose.c:58
/home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/readline.so(+0x3e4b)
[0x7f41cfed8e4b] readline.c:465
/home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/readline.so(+0x3ecb)
[0x7f41cfed8ecb] readline.c:494
./ruby(+0x1581dc) [0x7f41d16c81dc]
./ruby(+0x158d10) [0x7f41d16c8d10]
./ruby(+0x158e1d) [0x7f41d16c8e1d]
./ruby(+0x1598d5) [0x7f41d16c98d5]
./ruby(+0x15a0b4) [0x7f41d16ca0b4]
./ruby(+0x15db38) [0x7f41d16cdb38]
./ruby(+0x16d2ff) [0x7f41d16dd2ff]
./ruby(rb_iseq_eval_main+0x34) [0x7f41d16de176]
./ruby(+0x25e05) [0x7f41d1595e05]
./ruby(ruby_exec_node+0x24) [0x7f41d1595f1e]
./ruby(ruby_run_node+0x3e) [0x7f41d1595ef1]
./ruby(+0x23fa1) [0x7f41d1593fa1]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xfd)
[0x7f41d0501ead] libc-start.c:228
./ruby(+0x23e29) [0x7f41d1593e29]

-- Other runtime information -----------------------------------------------

* Loaded script: -e

* Loaded features:

    0 enumerator.so
    1 /home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/enc/encdb.so
    2 /home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/enc/trans/transdb.so
    3 /home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/rbconfig.rb
    4 /home/akr/tst2/lib/ruby/2.1.0/rubygems/compatibility.rb
    5 /home/akr/tst2/lib/ruby/2.1.0/rubygems/defaults.rb
    6 /home/akr/tst2/lib/ruby/2.1.0/rubygems/deprecate.rb
    7 /home/akr/tst2/lib/ruby/2.1.0/rubygems/errors.rb
    8 /home/akr/tst2/lib/ruby/2.1.0/rubygems/version.rb
    9 /home/akr/tst2/lib/ruby/2.1.0/rubygems/requirement.rb
   10 /home/akr/tst2/lib/ruby/2.1.0/rubygems/platform.rb
   11 /home/akr/tst2/lib/ruby/2.1.0/rubygems/basic_specification.rb
   12 /home/akr/tst2/lib/ruby/2.1.0/rubygems/stub_specification.rb
   13 /home/akr/tst2/lib/ruby/2.1.0/rubygems/specification.rb
   14 /home/akr/tst2/lib/ruby/2.1.0/rubygems/exceptions.rb
   15 /home/akr/tst2/lib/ruby/2.1.0/rubygems/core_ext/kernel_gem.rb
   16 /home/akr/tst2/lib/ruby/2.1.0/thread.rb
   17 /home/akr/tst2/lib/ruby/2.1.0/monitor.rb
   18 /home/akr/tst2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb
   19 /home/akr/tst2/lib/ruby/2.1.0/rubygems.rb
   20 /home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/readline.so

* Process memory map:

7f41cf62d000-7f41cf642000 r-xp 00000000 fe:00 9699332
  /lib/x86_64-linux-gnu/libgcc_s.so.1
7f41cf642000-7f41cf842000 ---p 00015000 fe:00 9699332
  /lib/x86_64-linux-gnu/libgcc_s.so.1
7f41cf842000-7f41cf843000 rw-p 00015000 fe:00 9699332
  /lib/x86_64-linux-gnu/libgcc_s.so.1
7f41cf843000-7f41cf868000 r-xp 00000000 fe:00 9699393
  /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f41cf868000-7f41cfa67000 ---p 00025000 fe:00 9699393
  /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f41cfa67000-7f41cfa6b000 r--p 00024000 fe:00 9699393
  /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f41cfa6b000-7f41cfa6c000 rw-p 00028000 fe:00 9699393
  /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f41cfa6c000-7f41cfa8d000 r-xp 00000000 fe:00 9699399
  /lib/x86_64-linux-gnu/libncurses.so.5.9
7f41cfa8d000-7f41cfc8c000 ---p 00021000 fe:00 9699399
  /lib/x86_64-linux-gnu/libncurses.so.5.9
7f41cfc8c000-7f41cfc8d000 r--p 00020000 fe:00 9699399
  /lib/x86_64-linux-gnu/libncurses.so.5.9
7f41cfc8d000-7f41cfc8e000 rw-p 00021000 fe:00 9699399
  /lib/x86_64-linux-gnu/libncurses.so.5.9
7f41cfc8e000-7f41cfccb000 r-xp 00000000 fe:00 9699466
  /lib/x86_64-linux-gnu/libreadline.so.6.2
7f41cfccb000-7f41cfecb000 ---p 0003d000 fe:00 9699466
  /lib/x86_64-linux-gnu/libreadline.so.6.2
7f41cfecb000-7f41cfecd000 r--p 0003d000 fe:00 9699466
  /lib/x86_64-linux-gnu/libreadline.so.6.2
7f41cfecd000-7f41cfed3000 rw-p 0003f000 fe:00 9699466
  /lib/x86_64-linux-gnu/libreadline.so.6.2
7f41cfed3000-7f41cfed5000 rw-p 00000000 00:00 0
7f41cfed5000-7f41cfedd000 r-xp 00000000 fe:00 3541664
  /home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/readline.so
7f41cfedd000-7f41d00dd000 ---p 00008000 fe:00 3541664
  /home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/readline.so
7f41d00dd000-7f41d00de000 rw-p 00008000 fe:00 3541664
  /home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/readline.so
7f41d00de000-7f41d00e0000 r-xp 00000000 fe:00 3938033
  /home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/enc/trans/transdb.so
7f41d00e0000-7f41d02e0000 ---p 00002000 fe:00 3938033
  /home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/enc/trans/transdb.so
7f41d02e0000-7f41d02e1000 rw-p 00002000 fe:00 3938033
  /home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/enc/trans/transdb.so
7f41d02e1000-7f41d02e3000 r-xp 00000000 fe:00 3938046
  /home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/enc/encdb.so
7f41d02e3000-7f41d04e2000 ---p 00002000 fe:00 3938046
  /home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/enc/encdb.so
7f41d04e2000-7f41d04e3000 rw-p 00001000 fe:00 3938046
  /home/akr/tst2/lib/ruby/2.1.0/x86_64-linux/enc/encdb.so
7f41d04e3000-7f41d0663000 r-xp 00000000 fe:00 9699347
  /lib/x86_64-linux-gnu/libc-2.13.so
7f41d0663000-7f41d0863000 ---p 00180000 fe:00 9699347
  /lib/x86_64-linux-gnu/libc-2.13.so
7f41d0863000-7f41d0867000 r--p 00180000 fe:00 9699347
  /lib/x86_64-linux-gnu/libc-2.13.so
7f41d0867000-7f41d0868000 rw-p 00184000 fe:00 9699347
  /lib/x86_64-linux-gnu/libc-2.13.so
7f41d0868000-7f41d086d000 rw-p 00000000 00:00 0
7f41d086d000-7f41d08ee000 r-xp 00000000 fe:00 9699344
  /lib/x86_64-linux-gnu/libm-2.13.so
7f41d08ee000-7f41d0aed000 ---p 00081000 fe:00 9699344
  /lib/x86_64-linux-gnu/libm-2.13.so
7f41d0aed000-7f41d0aee000 r--p 00080000 fe:00 9699344
  /lib/x86_64-linux-gnu/libm-2.13.so
7f41d0aee000-7f41d0aef000 rw-p 00081000 fe:00 9699344
  /lib/x86_64-linux-gnu/libm-2.13.so
7f41d0aef000-7f41d0af7000 r-xp 00000000 fe:00 9699348
  /lib/x86_64-linux-gnu/libcrypt-2.13.so
7f41d0af7000-7f41d0cf6000 ---p 00008000 fe:00 9699348
  /lib/x86_64-linux-gnu/libcrypt-2.13.so
7f41d0cf6000-7f41d0cf7000 r--p 00007000 fe:00 9699348
  /lib/x86_64-linux-gnu/libcrypt-2.13.so
7f41d0cf7000-7f41d0cf8000 rw-p 00008000 fe:00 9699348
  /lib/x86_64-linux-gnu/libcrypt-2.13.so
7f41d0cf8000-7f41d0d26000 rw-p 00000000 00:00 0
7f41d0d26000-7f41d0d28000 r-xp 00000000 fe:00 9699340
  /lib/x86_64-linux-gnu/libdl-2.13.so
7f41d0d28000-7f41d0f28000 ---p 00002000 fe:00 9699340
  /lib/x86_64-linux-gnu/libdl-2.13.so
7f41d0f28000-7f41d0f29000 r--p 00002000 fe:00 9699340
  /lib/x86_64-linux-gnu/libdl-2.13.so
7f41d0f29000-7f41d0f2a000 rw-p 00003000 fe:00 9699340
  /lib/x86_64-linux-gnu/libdl-2.13.so
7f41d0f2a000-7f41d0f31000 r-xp 00000000 fe:00 9699342
  /lib/x86_64-linux-gnu/librt-2.13.so
7f41d0f31000-7f41d1130000 ---p 00007000 fe:00 9699342
  /lib/x86_64-linux-gnu/librt-2.13.so
7f41d1130000-7f41d1131000 r--p 00006000 fe:00 9699342
  /lib/x86_64-linux-gnu/librt-2.13.so
7f41d1131000-7f41d1132000 rw-p 00007000 fe:00 9699342
  /lib/x86_64-linux-gnu/librt-2.13.so
7f41d1132000-7f41d1149000 r-xp 00000000 fe:00 9699337
  /lib/x86_64-linux-gnu/libpthread-2.13.so
7f41d1149000-7f41d1348000 ---p 00017000 fe:00 9699337
  /lib/x86_64-linux-gnu/libpthread-2.13.so
7f41d1348000-7f41d1349000 r--p 00016000 fe:00 9699337
  /lib/x86_64-linux-gnu/libpthread-2.13.so
7f41d1349000-7f41d134a000 rw-p 00017000 fe:00 9699337
  /lib/x86_64-linux-gnu/libpthread-2.13.so
7f41d134a000-7f41d134e000 rw-p 00000000 00:00 0
7f41d134e000-7f41d136e000 r-xp 00000000 fe:00 9699350
  /lib/x86_64-linux-gnu/ld-2.13.so
7f41d144d000-7f41d1554000 rw-p 00000000 00:00 0
7f41d1563000-7f41d1564000 rw-p 00000000 00:00 0
7f41d1565000-7f41d1567000 rw-p 00000000 00:00 0
7f41d1567000-7f41d1568000 ---p 00000000 00:00 0
7f41d1568000-7f41d156d000 rw-p 00000000 00:00 0
7f41d156d000-7f41d156e000 r--p 0001f000 fe:00 9699350
  /lib/x86_64-linux-gnu/ld-2.13.so
7f41d156e000-7f41d156f000 rw-p 00020000 fe:00 9699350
  /lib/x86_64-linux-gnu/ld-2.13.so
7f41d156f000-7f41d1570000 rw-p 00000000 00:00 0
7f41d1570000-7f41d1807000 r-xp 00000000 fe:00 3408492
  /home/akr/tst2/ruby/ruby
7f41d1a06000-7f41d1a0d000 rw-p 00296000 fe:00 3408492
  /home/akr/tst2/ruby/ruby
7f41d1a0d000-7f41d1a32000 rw-p 00000000 00:00 0
7f41d39db000-7f41d3dfa000 rw-p 00000000 00:00 0                          [heap]
7fffea934000-7fffea955000 rw-p 00000000 00:00 0                          [stack]
7fffea9ff000-7fffeaa00000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0
  [vsyscall]


[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
-- 
[田中 哲][たなか あきら][Tanaka Akira]

In This Thread

Prev Next