Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2016-09-20 08:42:03 +0300
committerRuben Davila <rdavila84@gmail.com>2016-09-20 19:07:49 +0300
commit30e98e486a61ab52573b5b5cdce43966af4268ce (patch)
treeddd66b931c47d07c053ee7f62eef3a1026a8febd /lib
parent3d26b41c4a4a8e3cc1b5c6419cd0b2a7f8d4f945 (diff)
Merge branch 'strip-key-comments-for-gitlab-shell' into 'master'
Strip comments before sending keys to gitlab-shell ## Why was this MR needed? https://gitlab.com/gitlab-org/gitlab-ce/issues/22167 encoding issues in comment text. ## What are the relevant issue numbers? https://gitlab.com/gitlab-org/gitlab-ce/issues/22167 See merge request !6381
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/backend/shell.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/gitlab/backend/shell.rb b/lib/gitlab/backend/shell.rb
index c412249a01e..79eac66b364 100644
--- a/lib/gitlab/backend/shell.rb
+++ b/lib/gitlab/backend/shell.rb
@@ -6,7 +6,12 @@ module Gitlab
KeyAdder = Struct.new(:io) do
def add_key(id, key)
- key.gsub!(/[[:space:]]+/, ' ').strip!
+ key = Gitlab::Shell.strip_key(key)
+ # Newline and tab are part of the 'protocol' used to transmit id+key to the other end
+ if key.include?("\t") || key.include?("\n")
+ raise Error.new("Invalid key: #{key.inspect}")
+ end
+
io.puts("#{id}\t#{key}")
end
end
@@ -16,6 +21,10 @@ module Gitlab
@version_required ||= File.read(Rails.root.
join('GITLAB_SHELL_VERSION')).strip
end
+
+ def strip_key(key)
+ key.split(/ /)[0, 2].join(' ')
+ end
end
# Init new repository
@@ -107,7 +116,7 @@ module Gitlab
#
def add_key(key_id, key_content)
Gitlab::Utils.system_silent([gitlab_shell_keys_path,
- 'add-key', key_id, key_content])
+ 'add-key', key_id, self.class.strip_key(key_content)])
end
# Batch-add keys to authorized_keys