summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-11-27 08:54:59 +0000
committerDouwe Maan <douwe@gitlab.com>2018-11-27 08:54:59 +0000
commit124a0cab33f6b9abda40351d2d5b4c382d514460 (patch)
treedcab2ba77342e335f79b61e5ef006765bcabf677
parentea8f0f3bcc02e26f6dbb7f40b3575bbaac852328 (diff)
parente36c347ff9827d6d14c6a8b9e217e085a3c3a498 (diff)
downloadgitlab-ce-124a0cab33f6b9abda40351d2d5b4c382d514460.tar.gz
Merge branch 'sh-handle-string-null-bytes' into 'master'
Gracefully handle references with null bytes Closes #54466 See merge request gitlab-org/gitlab-ce!23365
-rw-r--r--changelogs/unreleased/sh-handle-string-null-bytes.yml5
-rw-r--r--lib/gitlab/git_ref_validator.rb6
-rw-r--r--spec/lib/gitlab/git_ref_validator_spec.rb1
3 files changed, 11 insertions, 1 deletions
diff --git a/changelogs/unreleased/sh-handle-string-null-bytes.yml b/changelogs/unreleased/sh-handle-string-null-bytes.yml
new file mode 100644
index 00000000000..edc045274e3
--- /dev/null
+++ b/changelogs/unreleased/sh-handle-string-null-bytes.yml
@@ -0,0 +1,5 @@
+---
+title: Gracefully handle references with null bytes
+merge_request: 23365
+author:
+type: fixed
diff --git a/lib/gitlab/git_ref_validator.rb b/lib/gitlab/git_ref_validator.rb
index a90b69ff42b..3f13ebeb9d0 100644
--- a/lib/gitlab/git_ref_validator.rb
+++ b/lib/gitlab/git_ref_validator.rb
@@ -13,7 +13,11 @@ module Gitlab
return false if ref_name.start_with?(*not_allowed_prefixes)
return false if ref_name == 'HEAD'
- Rugged::Reference.valid_name? "refs/heads/#{ref_name}"
+ begin
+ Rugged::Reference.valid_name?("refs/heads/#{ref_name}")
+ rescue ArgumentError
+ return false
+ end
end
end
end
diff --git a/spec/lib/gitlab/git_ref_validator_spec.rb b/spec/lib/gitlab/git_ref_validator_spec.rb
index ba7fb168a3b..3ab04a1c46d 100644
--- a/spec/lib/gitlab/git_ref_validator_spec.rb
+++ b/spec/lib/gitlab/git_ref_validator_spec.rb
@@ -27,4 +27,5 @@ describe Gitlab::GitRefValidator do
it { expect(described_class.validate('-branch')).to be_falsey }
it { expect(described_class.validate('.tag')).to be_falsey }
it { expect(described_class.validate('my branch')).to be_falsey }
+ it { expect(described_class.validate("\xA0\u0000\xB0")).to be_falsey }
end