卜部昌平のあまりreblogしないtumblr RSS

Archive

Apr
8th
Thu
permalink

[ruby] Class.allocateが拓く(新しい地平 or バグの鉱脈)について

今日発見したんだけどClass.allocateが禁止されてないわけよ。

だからどうしたと思うかもしれないけど、これさ、ちょっとひねって

c = Class.allocate
d = Class.allocate
c.send :initialize, d
d.send :initialize, c

ってやると、cとdって互いに互いを継承しあっているという、あらゆるすべての前提条件をまるっきり無視した子ができるわけ。おかしかろ? RubyのクラスはすべからくObjectから生えるんじゃなかったのかよ。

でさ、まあそんだけだとあらゆるすべてのメソッド定義がない(BasicObjectよりもまっさら、本気でなんもない)から、とりあえずallocateだけBasicObjectから引っ張ってくるよね。

require 'dl'
DL.dlopen do |h|
  geta = h['rb_get_alloc_func']
  seta = h['rb_define_alloc_func']
  getf = DL::CFunc.new geta, DL::TYPE_VOIDP
  setf = DL::CFunc.new seta
  setf[[ DL.dlwrap(c), getf[[ DL.dlwrap(BasicObject) ]]]]
end

puts "yes" if c.allocate

うわぁ…これやべー。これやべーよ。Rubyはじまったよ。

とりあえずこの方向でSEGVさせる方法を募集します。こんな機能危なすぎる。はやいうちにこれ不可能ってことにしとかないと…

  1. sighingdog reblogged this from shyouhei
  2. d0gf00d reblogged this from shyouhei
  3. deepneko reblogged this from shyouhei
  4. yosshi reblogged this from shyouhei
  5. mitukiii reblogged this from tamoot
  6. tamoot reblogged this from shyouhei
  7. sanemat reblogged this from shyouhei
  8. atm09td reblogged this from ukar
  9. hsbt reblogged this from shyouhei
  10. ukar reblogged this from shyouhei
  11. pipco reblogged this from shyouhei
  12. hajimehoshi reblogged this from shyouhei
  13. send reblogged this from shyouhei
  14. shyouhei posted this