exec_sandbox 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe ExecSandbox::Wait4 do
4
+ describe '#wait4' do
5
+ describe 'write_arg.rb' do
6
+ before do
7
+ pid = Kernel.fork { Process.exec bin_fixture(:exit_arg), '42' }
8
+ @status = ExecSandbox::Wait4.wait4 pid
9
+ end
10
+
11
+ it 'should have the correct exit status' do
12
+ @status[:exit_code].should == 42
13
+ end
14
+
15
+ it 'should not take more than 1s of user time' do
16
+ @status[:user_time].should < 1
17
+ end
18
+
19
+ it 'should not take more than 1s of system time' do
20
+ @status[:system_time].should < 1
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Allocates a buffer sized according to the second argument and writes it to the
4
+ # file indicated by the first argument.
5
+
6
+ buffer = String.new "\xFE" * ARGV[1].to_i
7
+ File.open(ARGV[0], 'wb') do |f|
8
+ f.write buffer
9
+ f.flush
10
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Churns away at math for a number of seconds indicated by the second argument,
4
+ # then outputs a '+' and exists.
5
+
6
+ start = Time.now
7
+ File.open(ARGV[0], 'wb') do |f|
8
+ f.sync = true
9
+ loop do
10
+ j = 0
11
+ 1.upto(1_000_000) { |i| j = i * i + 100 }
12
+ break if Time.now - start >= ARGV[1].to_i
13
+ end
14
+ f.write '+'
15
+ f.flush
16
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Writes STDIN to STDOUT twice.
4
+
5
+ bits = STDIN.read
6
+ 2.times { STDOUT.write bits }
7
+ STDOUT.flush
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Exits with the code given in the first argument.
4
+
5
+ Process.exit ARGV[0].to_i
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Forks a number of processes matching second argument, each process writes a
4
+ # + to the file pointed by the first argument.
5
+
6
+ proc_count = ARGV[1].to_i
7
+ pids = Array.new proc_count
8
+
9
+ File.open(ARGV[0], 'wb') do |f|
10
+ f.sync = true
11
+ 0.upto(proc_count - 1) do |i|
12
+ pids[i] = fork do
13
+ f.write '+'
14
+ sleep 1
15
+ end
16
+ end
17
+ 0.upto(proc_count - 1) { |i| Process.waitpid(pids[i]) }
18
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Writes the current directory to the file indicated by the first argument.
4
+
5
+ File.open(ARGV[0], 'wb') do |f|
6
+ f.write Dir.pwd
7
+ f.flush
8
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Writes its second argument to the file indicated by the first argument.
4
+
5
+ File.open(ARGV[0], 'wb') do |f|
6
+ f.write ARGV[1]
7
+ f.flush
8
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'exec_sandbox'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,7 @@
1
+ # Path to one of the fixture code files.
2
+ #
3
+ # @param [Symbol] fixture_id the name of the code file
4
+ # @return [String] fully-qualified path to the code file
5
+ def bin_fixture(fixture_id)
6
+ File.expand_path "#{File.dirname(__FILE__)}/../fixtures/#{fixture_id.to_s}.rb"
7
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exec_sandbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Victor Costan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-13 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ffi
16
+ requirement: &23606780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.9
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *23606780
25
+ - !ruby/object:Gem::Dependency
26
+ name: rdoc
27
+ requirement: &23606160 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '3.10'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *23606160
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &23605400 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 2.6.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *23605400
47
+ - !ruby/object:Gem::Dependency
48
+ name: yard
49
+ requirement: &23604760 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.7.2
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *23604760
58
+ - !ruby/object:Gem::Dependency
59
+ name: yard-rspec
60
+ requirement: &23604040 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0.1'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *23604040
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: &23603320 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: 1.0.21
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *23603320
80
+ - !ruby/object:Gem::Dependency
81
+ name: jeweler
82
+ requirement: &23602620 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: 1.6.4
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *23602620
91
+ - !ruby/object:Gem::Dependency
92
+ name: rcov
93
+ requirement: &23601780 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *23601780
102
+ description: Temporary users and groups, rlimits
103
+ email: costan@gmail.com
104
+ executables: []
105
+ extensions: []
106
+ extra_rdoc_files:
107
+ - LICENSE.txt
108
+ - README.rdoc
109
+ files:
110
+ - .document
111
+ - .project
112
+ - .rspec
113
+ - Gemfile
114
+ - Gemfile.lock
115
+ - LICENSE.txt
116
+ - README.rdoc
117
+ - Rakefile
118
+ - VERSION
119
+ - lib/exec_sandbox.rb
120
+ - lib/exec_sandbox/sandbox.rb
121
+ - lib/exec_sandbox/spawn.rb
122
+ - lib/exec_sandbox/users.rb
123
+ - lib/exec_sandbox/wait4.rb
124
+ - spec/exec_sandbox/sandbox_spec.rb
125
+ - spec/exec_sandbox/spawn_spec.rb
126
+ - spec/exec_sandbox/users_spec.rb
127
+ - spec/exec_sandbox/wait4_spec.rb
128
+ - spec/fixtures/buffer.rb
129
+ - spec/fixtures/churn.rb
130
+ - spec/fixtures/duplicate.rb
131
+ - spec/fixtures/exit_arg.rb
132
+ - spec/fixtures/fork.rb
133
+ - spec/fixtures/pwd.rb
134
+ - spec/fixtures/write_arg.rb
135
+ - spec/spec_helper.rb
136
+ - spec/support/code_fixture.rb
137
+ homepage: http://github.com/pwnall/exec_sandbox
138
+ licenses:
139
+ - MIT
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ segments:
151
+ - 0
152
+ hash: -3535790192517307381
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ requirements: []
160
+ rubyforge_project:
161
+ rubygems_version: 1.8.11
162
+ signing_key:
163
+ specification_version: 3
164
+ summary: Run foreign binaries using POSIX sandboxing features
165
+ test_files: []