Project

General

Profile

Bug #15262 ยป adder-test2.rb

Simplified version of the initial exploit - larskanis (Lars Kanis), 10/29/2018 08:34 AM

 
1
require "weakref"
2

    
3
Thread.abort_on_exception = true
4

    
5
class Adder
6
  def self.start_adder(obj)
7
    obj.add
8
  end
9

    
10
  def initialize
11
    @qu = Queue.new
12
    count = 10
13
    count.times do
14
      Thread.new(WeakRef.new(self), &self.class.method(:start_adder))
15
    end
16
    count.times do
17
      @qu.deq
18
    end
19
  end
20

    
21
  def add
22
    @qu.enq true
23
  end
24
end
25

    
26
def test_adder
27
  10.times.map do
28
    Thread.new do
29
      Adder.new
30
    end
31
  end.each(&:join)
32
end
33

    
34
100.times do
35
  test_adder
36
end