file-temp 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/CHANGES +4 -0
  2. data/README +4 -1
  3. data/ext/temp.c +9 -6
  4. data/test/tc_file_temp.rb +7 -1
  5. metadata +45 -38
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ = 1.0.0
2
+ * Added security via umask().
3
+ * Version bump to 1.0.0.
4
+
1
5
  = 0.1.2 - 6-Jun-2007
2
6
  * Gemspec fix (forgot the temp.h file - oops).
3
7
  * Added an extra test.
data/README CHANGED
@@ -25,6 +25,9 @@
25
25
  Ruby's tempfile.rb is overwrought and susceptible to race conditions. This
26
26
  This library uses your system's native tmpfile() or mkstemp() functions
27
27
  instead of trying to handle race conditions manually via pure Ruby.
28
+
29
+ This library is also more secure because it restricts file permission via
30
+ umask() for files created with mkstemp().
28
31
 
29
32
  = Other libraries
30
33
  I am aware of Cian Synnott's ruby-stemp project. However, I don't like the
@@ -40,7 +43,7 @@
40
43
  Ruby's
41
44
 
42
45
  = Copyright
43
- (C) 2007 Daniel J. Berger
46
+ (C) 2007-2008 Daniel J. Berger
44
47
  All Rights Reserved
45
48
 
46
49
  = Warranty
data/ext/temp.c CHANGED
@@ -1,5 +1,6 @@
1
1
  #include <ruby.h>
2
2
  #include <stdio.h>
3
+ #include <sys/stat.h>
3
4
 
4
5
  #ifdef HAVE__SOPEN_S
5
6
  #include <share.h>
@@ -14,7 +15,7 @@
14
15
  #define P_tmpdir "/tmp"
15
16
  #endif
16
17
 
17
- #define VERSION "0.1.2"
18
+ #define VERSION "1.0.0"
18
19
 
19
20
  VALUE cFileTemp;
20
21
 
@@ -59,16 +60,18 @@ static VALUE tempfile_init(int argc, VALUE* argv, VALUE self){
59
60
  if(!fptr)
60
61
  rb_sys_fail("tmpfile()");
61
62
  #endif
62
-
63
63
  v_args[0] = INT2FIX(fileno(fptr));
64
64
  }
65
65
  else{
66
- int fd;
66
+ int fd, omask;
67
67
 
68
68
  if(NIL_P(v_template))
69
69
  v_template = rb_str_new2("rb_file_temp_XXXXXX");
70
70
 
71
+ /* Set the umask to improve security */
72
+ omask = umask(077);
71
73
  fd = mkstemp(StringValuePtr(v_template));
74
+ umask(omask);
72
75
 
73
76
  if(fd < 0)
74
77
  rb_sys_fail("mkstemp()");
@@ -77,7 +80,7 @@ static VALUE tempfile_init(int argc, VALUE* argv, VALUE self){
77
80
  }
78
81
 
79
82
  /* This bit of explicitness is necessary for MS Windows */
80
- v_args[1] = rb_str_new2("wb");
83
+ v_args[1] = rb_str_new2("wb+");
81
84
 
82
85
  return rb_call_super(2, v_args);
83
86
  }
@@ -105,13 +108,13 @@ void Init_temp(){
105
108
  rb_define_method(cFileTemp, "initialize", tempfile_init, -1);
106
109
 
107
110
  /* Singleton Methods */
108
- rb_define_singleton_method(cFileTemp, "tmpnam", tempfile_tmpnam, 0);
111
+ rb_define_singleton_method(cFileTemp, "temp_name", tempfile_tmpnam, 0);
109
112
 
110
113
  /* Constants */
111
114
 
112
115
  /* ENV['P_tmpdir']: Your system's tmpdir */
113
116
  rb_define_const(cFileTemp, "TMPDIR", rb_str_new2(P_tmpdir));
114
117
 
115
- /* 0.1.2: The version of this library */
118
+ /* 0.1.3: The version of this library */
116
119
  rb_define_const(cFileTemp, "VERSION", rb_str_new2(VERSION));
117
120
  }
data/test/tc_file_temp.rb CHANGED
@@ -14,7 +14,13 @@ class TC_File_Temp < Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  def test_file_temp_version
17
- assert_equal('0.1.2', FileTemp::VERSION)
17
+ assert_equal('1.0.0', FileTemp::VERSION)
18
+ end
19
+
20
+ def test_file_temp_threaded
21
+ threads = []
22
+ assert_nothing_raised{ 100.times{ threads << Thread.new{ FileTemp.new }}}
23
+ assert_nothing_raised{ threads.join }
18
24
  end
19
25
 
20
26
  def test_file_temp_tmpdir
metadata CHANGED
@@ -1,54 +1,61 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: file-temp
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.2
7
- date: 2007-06-06 00:00:00 -06:00
8
- summary: An alternative way to generate tempfiles
9
- require_paths:
10
- - lib
11
- email: djberg96@gmail.com
12
- homepage: http://www.rubyforge.org/projects/shards
13
- rubyforge_project: shards
14
- description: An alternative way to generate tempfiles
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.8.0
24
- version:
4
+ version: 1.0.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Daniel J. Berger
31
- files:
32
- - test/tc_file_temp.rb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-12 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: An alternative way to generate tempfiles
17
+ email: djberg96@gmail.com
18
+ executables: []
19
+
20
+ extensions:
21
+ - ext/extconf.rb
22
+ extra_rdoc_files:
33
23
  - CHANGES
34
- - MANIFEST
35
24
  - README
36
- - Rakefile
25
+ - MANIFEST
37
26
  - ext/temp.c
38
- test_files:
27
+ files:
39
28
  - test/tc_file_temp.rb
40
- rdoc_options: []
41
-
42
- extra_rdoc_files:
43
29
  - CHANGES
44
- - README
45
30
  - MANIFEST
31
+ - Rakefile
32
+ - README
46
33
  - ext/temp.c
47
- executables: []
34
+ has_rdoc: true
35
+ homepage: http://www.rubyforge.org/projects/shards
36
+ post_install_message:
37
+ rdoc_options: []
48
38
 
49
- extensions:
50
- - ext/extconf.rb
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.8.0
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
51
53
  requirements: []
52
54
 
53
- dependencies: []
54
-
55
+ rubyforge_project: shards
56
+ rubygems_version: 1.0.1
57
+ signing_key:
58
+ specification_version: 2
59
+ summary: An alternative way to generate tempfiles
60
+ test_files:
61
+ - test/tc_file_temp.rb