secure 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/secure.rb +2 -0
- data/lib/secure/child_process.rb +31 -0
- data/lib/secure/parent_process.rb +12 -0
- data/lib/secure/runner.rb +13 -14
- data/lib/secure/version.rb +1 -1
- metadata +6 -4
data/lib/secure.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Secure
|
2
|
+
class ChildProcess
|
3
|
+
def initialize(opts, read_file, write_file)
|
4
|
+
read_file.close
|
5
|
+
@pipe = write_file
|
6
|
+
@timeout = opts[:timeout] || 1
|
7
|
+
end
|
8
|
+
|
9
|
+
def guard_threads
|
10
|
+
@guard_threads || []
|
11
|
+
end
|
12
|
+
|
13
|
+
def safely_run_block
|
14
|
+
thread = Thread.start do
|
15
|
+
$SAFE=3
|
16
|
+
yield
|
17
|
+
end
|
18
|
+
|
19
|
+
guard_threads << GuardThread.kill_thread_on_timeout(@timeout, thread)
|
20
|
+
|
21
|
+
Response.success(thread.value)
|
22
|
+
rescue Exception => e
|
23
|
+
Response.error(e)
|
24
|
+
end
|
25
|
+
|
26
|
+
def execute
|
27
|
+
ret = safely_run_block { yield }
|
28
|
+
@pipe.write(Marshal.dump(ret))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/secure/runner.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
1
|
module Secure
|
2
2
|
class Runner
|
3
3
|
def initialize(opts)
|
4
|
-
@
|
5
|
-
end
|
6
|
-
|
7
|
-
def guard_threads
|
8
|
-
@guard_threads || []
|
4
|
+
@opts = opts
|
9
5
|
end
|
10
6
|
|
11
7
|
def run
|
12
|
-
|
13
|
-
$SAFE=3
|
14
|
-
Response.success(yield)
|
15
|
-
end
|
8
|
+
read_file, write_file = IO.pipe
|
16
9
|
|
17
|
-
|
10
|
+
child = fork do
|
11
|
+
begin
|
12
|
+
ChildProcess.new(@opts, read_file, write_file).execute { yield }
|
13
|
+
ensure
|
14
|
+
exit!
|
15
|
+
end
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
Response.error(e)
|
18
|
+
Process.wait(child)
|
19
|
+
ParentProcess.new(read_file, write_file).execute
|
22
20
|
ensure
|
23
|
-
|
21
|
+
read_file.close unless read_file.closed?
|
22
|
+
write_file.close unless write_file.closed?
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
data/lib/secure/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.5
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tejas Dinkar
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-30 00:00:00 +05:30
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -33,8 +33,10 @@ files:
|
|
33
33
|
- Gemfile
|
34
34
|
- Rakefile
|
35
35
|
- lib/secure.rb
|
36
|
+
- lib/secure/child_process.rb
|
36
37
|
- lib/secure/errors.rb
|
37
38
|
- lib/secure/guard_thread.rb
|
39
|
+
- lib/secure/parent_process.rb
|
38
40
|
- lib/secure/response.rb
|
39
41
|
- lib/secure/runner.rb
|
40
42
|
- lib/secure/version.rb
|