File tree Expand file tree Collapse file tree 9 files changed +147
-2
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 9 files changed +147
-2
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ Bug fixes:
8
8
9
9
* Fix ` StringIO ` to set position correctly after reading multi-byte characters (#2207 , @aardvark179 ).
10
10
* Update ` Process ` methods to use ` module_function ` (@bjfish ).
11
+ * Fix ` File::Stat ` 's ` #executable? ` and ` #executable_real? ` predicates that unconditionally returned ` true ` for a superuser (#2690 , @andrykonchin ).
11
12
12
13
Compatibility:
13
14
Original file line number Diff line number Diff line change @@ -6,10 +6,20 @@ def match?
6
6
end
7
7
end
8
8
9
+ class RealSuperUserGuard < SpecGuard
10
+ def match?
11
+ Process . uid == 0
12
+ end
13
+ end
14
+
9
15
def as_superuser ( &block )
10
16
SuperUserGuard . new . run_if ( :as_superuser , &block )
11
17
end
12
18
19
+ def as_real_superuser ( &block )
20
+ RealSuperUserGuard . new . run_if ( :as_real_superuser , &block )
21
+ end
22
+
13
23
def as_user ( &block )
14
24
SuperUserGuard . new . run_unless ( :as_user , &block )
15
25
end
Original file line number Diff line number Diff line change 39
39
-> { @object . send ( @method , nil ) } . should raise_error ( TypeError )
40
40
-> { @object . send ( @method , false ) } . should raise_error ( TypeError )
41
41
end
42
+
43
+ platform_is_not :windows do
44
+ as_superuser do
45
+ context "when run by a superuser" do
46
+ before :each do
47
+ @file = tmp ( 'temp3.txt' )
48
+ touch @file
49
+ end
50
+
51
+ after :each do
52
+ rm_r @file
53
+ end
54
+
55
+ it "returns true if file owner has permission to execute" do
56
+ File . chmod ( 0766 , @file )
57
+ @object . send ( @method , @file ) . should == true
58
+ end
59
+
60
+ it "returns true if group has permission to execute" do
61
+ File . chmod ( 0676 , @file )
62
+ @object . send ( @method , @file ) . should == true
63
+ end
64
+
65
+ it "returns true if other have permission to execute" do
66
+ File . chmod ( 0667 , @file )
67
+ @object . send ( @method , @file ) . should == true
68
+ end
69
+
70
+ it "return false if nobody has permission to execute" do
71
+ File . chmod ( 0666 , @file )
72
+ @object . send ( @method , @file ) . should == false
73
+ end
74
+ end
75
+ end
76
+ end
42
77
end
43
78
44
79
describe :file_executable_missing , shared : true do
Original file line number Diff line number Diff line change 37
37
-> { @object . send ( @method , nil ) } . should raise_error ( TypeError )
38
38
-> { @object . send ( @method , false ) } . should raise_error ( TypeError )
39
39
end
40
+
41
+ platform_is_not :windows do
42
+ as_real_superuser do
43
+ context "when run by a real superuser" do
44
+ before :each do
45
+ @file = tmp ( 'temp3.txt' )
46
+ touch @file
47
+ end
48
+
49
+ after :each do
50
+ rm_r @file
51
+ end
52
+
53
+ it "returns true if file owner has permission to execute" do
54
+ File . chmod ( 0766 , @file )
55
+ @object . send ( @method , @file ) . should == true
56
+ end
57
+
58
+ it "returns true if group has permission to execute" do
59
+ File . chmod ( 0676 , @file )
60
+ @object . send ( @method , @file ) . should == true
61
+ end
62
+
63
+ it "returns true if other have permission to execute" do
64
+ File . chmod ( 0667 , @file )
65
+ @object . send ( @method , @file ) . should == true
66
+ end
67
+
68
+ it "return false if nobody has permission to execute" do
69
+ File . chmod ( 0666 , @file )
70
+ @object . send ( @method , @file ) . should == false
71
+ end
72
+ end
73
+ end
74
+ end
40
75
end
41
76
42
77
describe :file_executable_real_missing , shared : true do
Original file line number Diff line number Diff line change 24
24
it "accepts an object that has a #to_path method" do
25
25
@object . send ( @method , mock_to_path ( @file2 ) ) . should == true
26
26
end
27
+
28
+ platform_is_not :windows do
29
+ as_superuser do
30
+ context "when run by a superuser" do
31
+ it "returns true unconditionally" do
32
+ file = tmp ( 'temp.txt' )
33
+ touch file
34
+
35
+ File . chmod ( 0333 , file )
36
+ @object . send ( @method , file ) . should == true
37
+
38
+ rm_r file
39
+ end
40
+ end
41
+ end
42
+ end
27
43
end
28
44
29
45
describe :file_readable_missing , shared : true do
Original file line number Diff line number Diff line change 14
14
it "accepts an object that has a #to_path method" do
15
15
File . open ( @file , 'w' ) { @object . send ( @method , mock_to_path ( @file ) ) . should == true }
16
16
end
17
+
18
+ platform_is_not :windows do
19
+ as_real_superuser do
20
+ context "when run by a real superuser" do
21
+ it "returns true unconditionally" do
22
+ file = tmp ( 'temp.txt' )
23
+ touch file
24
+
25
+ File . chmod ( 0333 , file )
26
+ @object . send ( @method , file ) . should == true
27
+
28
+ rm_r file
29
+ end
30
+ end
31
+ end
32
+ end
17
33
end
18
34
19
35
describe :file_readable_real_missing , shared : true do
Original file line number Diff line number Diff line change 19
19
it "accepts an object that has a #to_path method" do
20
20
File . open ( @file , 'w' ) { @object . send ( @method , mock_to_path ( @file ) ) . should == true }
21
21
end
22
+
23
+ platform_is_not :windows do
24
+ as_superuser do
25
+ context "when run by a superuser" do
26
+ it "returns true unconditionally" do
27
+ file = tmp ( 'temp.txt' )
28
+ touch file
29
+
30
+ File . chmod ( 0555 , file )
31
+ @object . send ( @method , file ) . should == true
32
+
33
+ rm_r file
34
+ end
35
+ end
36
+ end
37
+ end
22
38
end
23
39
24
40
describe :file_writable_missing , shared : true do
Original file line number Diff line number Diff line change 24
24
-> { @object . send ( @method , nil ) } . should raise_error ( TypeError )
25
25
-> { @object . send ( @method , false ) } . should raise_error ( TypeError )
26
26
end
27
+
28
+ platform_is_not :windows do
29
+ as_real_superuser do
30
+ context "when run by a real superuser" do
31
+ it "returns true unconditionally" do
32
+ file = tmp ( 'temp.txt' )
33
+ touch file
34
+
35
+ File . chmod ( 0555 , file )
36
+ @object . send ( @method , file ) . should == true
37
+
38
+ rm_r file
39
+ end
40
+ end
41
+ end
42
+ end
27
43
end
28
44
29
45
describe :file_writable_real_missing , shared : true do
Original file line number Diff line number Diff line change @@ -131,14 +131,14 @@ def directory?
131
131
end
132
132
133
133
def executable?
134
- return true if superuser?
134
+ return mode & S_IXUGO != 0 if superuser?
135
135
return mode & S_IXUSR != 0 if owned?
136
136
return mode & S_IXGRP != 0 if grpowned?
137
137
mode & S_IXOTH != 0
138
138
end
139
139
140
140
def executable_real?
141
- return true if rsuperuser?
141
+ return mode & S_IXUGO != 0 if rsuperuser?
142
142
return mode & S_IXUSR != 0 if rowned?
143
143
return mode & S_IXGRP != 0 if rgrpowned?
144
144
mode & S_IXOTH != 0
You can’t perform that action at this time.
0 commit comments