This repository was archived by the owner on Apr 19, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Expand file tree Collapse file tree 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)
683683 end
684684
685685 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 |
687689 f . write contents
688690 end
689691 end
Original file line number Diff line number Diff line change @@ -117,15 +117,19 @@ def shell_escape(str)
117117 #
118118 # Returns Boolean
119119 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 )
121123 end
122124
123125 # Read a normal file from the filesystem.
124126 # +file+ is the relative path from the Git dir
125127 #
126128 # Returns the String contents of the file
127129 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 )
129133 end
130134
131135 # Write a normal file to the filesystem.
@@ -135,6 +139,7 @@ def fs_read(file)
135139 # Returns nothing
136140 def fs_write ( file , contents )
137141 path = File . join ( self . git_dir , file )
142+ raise "Invalid path: #{ path } " unless File . absolute_path ( path ) == path
138143 FileUtils . mkdir_p ( File . dirname ( path ) )
139144 File . open ( path , 'w' ) do |f |
140145 f . write ( contents )
You can’t perform that action at this time.
0 commit comments