diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2013-11-05 12:30:45 +0400 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2013-11-05 12:30:45 +0400 |
commit | 71f34f77b306e2517e18e198d227470cd8d0df7b (patch) | |
tree | 99bf4dbcd2b586b3df0669e933d5049648d4568a /lib | |
parent | 2ee04b120a142ee227cb860ffddb991ef31a6910 (diff) | |
parent | c46eaca91247ccf8e6fb3b691dad028e1b084ae3 (diff) |
Merge pull request #5500 from nkukard/esc-strings2
More escaping
Diffstat (limited to 'lib')
-rw-r--r-- | lib/backup/database.rb | 11 | ||||
-rw-r--r-- | lib/backup/repository.rb | 9 |
2 files changed, 11 insertions, 9 deletions
diff --git a/lib/backup/database.rb b/lib/backup/database.rb index c4fb2e2e159..6ada5bb4ea2 100644 --- a/lib/backup/database.rb +++ b/lib/backup/database.rb @@ -1,4 +1,5 @@ require 'yaml' +require 'shellwords' module Backup class Database @@ -13,20 +14,20 @@ module Backup def dump case config["adapter"] when /^mysql/ then - system("mysqldump #{mysql_args} #{config['database']} > #{db_file_name}") + system("mysqldump #{mysql_args} #{Shellwords.shellescape(config['database'])} > #{Shellwords.shellescape(db_file_name)}") when "postgresql" then pg_env - system("pg_dump #{config['database']} > #{db_file_name}") + system("pg_dump #{Shellwords.shellescape(config['database'])} > #{db_file_name}") end end def restore case config["adapter"] when /^mysql/ then - system("mysql #{mysql_args} #{config['database']} < #{db_file_name}") + system("mysql #{mysql_args} #{Shellwords.shellescape(config['database'])} < #{db_file_name}") when "postgresql" then pg_env - system("psql #{config['database']} -f #{db_file_name}") + system("psql #{Shellwords.shellescape(config['database'])} -f #{Shellwords.shellescape(db_file_name)}") end end @@ -45,7 +46,7 @@ module Backup 'encoding' => '--default-character-set', 'password' => '--password' } - args.map { |opt, arg| "#{arg}='#{config[opt]}'" if config[opt] }.compact.join(' ') + args.map { |opt, arg| "#{arg}=#{Shellwords.shellescape(config[opt])}" if config[opt] }.compact.join(' ') end def pg_env diff --git a/lib/backup/repository.rb b/lib/backup/repository.rb index 252201f11be..3649ff99d24 100644 --- a/lib/backup/repository.rb +++ b/lib/backup/repository.rb @@ -1,4 +1,5 @@ require 'yaml' +require 'shellwords' module Backup class Repository @@ -18,7 +19,7 @@ module Backup # Create namespace dir if missing FileUtils.mkdir_p(File.join(backup_repos_path, project.namespace.path)) if project.namespace - if system("cd #{path_to_repo(project)} > /dev/null 2>&1 && git bundle create #{path_to_bundle(project)} --all > /dev/null 2>&1") + if system("cd #{Shellwords.shellescape(path_to_repo(project))} > /dev/null 2>&1 && git bundle create #{Shellwords.shellescape(path_to_bundle(project))} --all > /dev/null 2>&1") puts "[DONE]".green else puts "[FAILED]".red @@ -30,7 +31,7 @@ module Backup print " * #{wiki.path_with_namespace} ... " if wiki.empty? puts " [SKIPPED]".cyan - elsif system("cd #{path_to_repo(wiki)} > /dev/null 2>&1 && git bundle create #{path_to_bundle(wiki)} --all > /dev/null 2>&1") + elsif system("cd #{Shellwords.shellescape(path_to_repo(wiki))} > /dev/null 2>&1 && git bundle create #{Shellwords.shellescape(path_to_bundle(wiki))} --all > /dev/null 2>&1") puts " [DONE]".green else puts " [FAILED]".red @@ -53,7 +54,7 @@ module Backup project.namespace.ensure_dir_exist if project.namespace - if system("git clone --bare #{path_to_bundle(project)} #{path_to_repo(project)} > /dev/null 2>&1") + if system("git clone --bare #{Shellwords.shellescape(path_to_bundle(project))} #{Shellwords.shellescape(path_to_repo(project))} > /dev/null 2>&1") puts "[DONE]".green else puts "[FAILED]".red @@ -63,7 +64,7 @@ module Backup if File.exists?(path_to_bundle(wiki)) print " * #{wiki.path_with_namespace} ... " - if system("git clone --bare #{path_to_bundle(wiki)} #{path_to_repo(wiki)} > /dev/null 2>&1") + if system("git clone --bare #{Shellwords.shellescape(path_to_bundle(wiki))} #{Shellwords.shellescape(path_to_repo(wiki))} > /dev/null 2>&1") puts " [DONE]".green else puts " [FAILED]".red |