File tree 2 files changed +10
-3
lines changed
2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -683,7 +683,9 @@ def self.create_initial_config(bare = false)
683
683
end
684
684
685
685
def self . add_file ( name , contents )
686
- File . open ( name , 'w' ) do |f |
686
+ path = File . join ( Dir . pwd , name )
687
+ raise "Invalid path: #{ path } " unless File . absolute_path ( path ) == path
688
+ File . open ( path , 'w' ) do |f |
687
689
f . write contents
688
690
end
689
691
end
Original file line number Diff line number Diff line change @@ -117,15 +117,19 @@ def shell_escape(str)
117
117
#
118
118
# Returns Boolean
119
119
def fs_exist? ( file )
120
- File . exist? ( File . join ( self . git_dir , file ) )
120
+ path = File . join ( self . git_dir , file )
121
+ raise "Invalid path: #{ path } " unless File . absolute_path ( path ) == path
122
+ File . exist? ( path )
121
123
end
122
124
123
125
# Read a normal file from the filesystem.
124
126
# +file+ is the relative path from the Git dir
125
127
#
126
128
# Returns the String contents of the file
127
129
def fs_read ( file )
128
- File . read ( File . join ( self . git_dir , file ) )
130
+ path = File . join ( self . git_dir , file )
131
+ raise "Invalid path: #{ path } " unless File . absolute_path ( path ) == path
132
+ File . read ( path )
129
133
end
130
134
131
135
# Write a normal file to the filesystem.
@@ -135,6 +139,7 @@ def fs_read(file)
135
139
# Returns nothing
136
140
def fs_write ( file , contents )
137
141
path = File . join ( self . git_dir , file )
142
+ raise "Invalid path: #{ path } " unless File . absolute_path ( path ) == path
138
143
FileUtils . mkdir_p ( File . dirname ( path ) )
139
144
File . open ( path , 'w' ) do |f |
140
145
f . write ( contents )
You can’t perform that action at this time.
0 commit comments