@@ -91,7 +91,7 @@ function update($event_name,$data) {
9191 $ this ->delete ($ event_name ,$ data );
9292
9393 // Get the new config file path
94- $ config_file_path = escapeshellcmd ($ this ->getmail_config_dir .'/ ' .$ data ["new " ]["source_server " ].'_ ' .$ data ["new " ]["source_username " ].'.conf ' );
94+ $ config_file_path = escapeshellcmd ($ this ->getmail_config_dir .'/ ' .$ this -> _clean_path ( $ data ["new " ]["source_server " ]) .'_ ' .$ this -> _clean_path ( $ data ["new " ]["source_username " ]) .'.conf ' );
9595 if (stristr ($ config_file_path , ".. " ) or stristr ($ config_file_path , "| " ) or stristr ($ config_file_path ,"; " ) or stristr ($ config_file_path ,'$ ' )) {
9696 $ app ->log ("Possibly faked path for getmail config file: ' $ config_file_path'. File is not written. " ,LOGLEVEL_ERROR );
9797 return false ;
@@ -155,14 +155,18 @@ function delete($event_name,$data) {
155155 $ getmail_config = $ app ->getconf ->get_server_config ($ conf ["server_id " ], 'getmail ' );
156156 $ this ->getmail_config_dir = $ getmail_config ["getmail_config_dir " ];
157157
158- $ config_file_path = escapeshellcmd ($ this ->getmail_config_dir .'/ ' .$ data ["old " ]["source_server " ].'_ ' .$ data ["old " ]["source_username " ].'.conf ' );
158+ $ config_file_path = escapeshellcmd ($ this ->getmail_config_dir .'/ ' .$ this -> _clean_path ( $ data ["old " ]["source_server " ]) .'_ ' .$ this -> _clean_path ( $ data ["old " ]["source_username " ]) .'.conf ' );
159159 if (stristr ($ config_file_path ,".. " ) || stristr ($ config_file_path ,"| " ) || stristr ($ config_file_path ,"; " ) || stristr ($ config_file_path ,'$ ' )) {
160160 $ app ->log ("Possibly faked path for getmail config file: ' $ config_file_path'. File is not written. " ,LOGLEVEL_ERROR );
161161 return false ;
162162 }
163163 if (is_file ($ config_file_path )) unlink ($ config_file_path );
164164 }
165165
166+ function _clean_path ($ input ) {
167+ return preg_replace ('/[^A-Za-z0-9\-_]/ ' , '_ ' , $ input );
168+ }
169+
166170
167171} // end class
168172
0 commit comments