Permalink
Browse files

fix signature/object leak in tag_create

If the message is not a string both the target object and tagger
signature were not freed.
  • Loading branch information...
1 parent 47eca07 commit b1a6ae2eed8d345e229b931fdf1f7759aed87da9 @nvloff nvloff committed with vmg Mar 31, 2013
Showing with 47 additions and 5 deletions.
  1. +7 −5 ext/rugged/rugged_tag.c
  2. +40 −0 test/tag_test.rb
View
@@ -185,22 +185,24 @@ static VALUE rb_git_tag_create(VALUE self, VALUE rb_repo, VALUE rb_data)
rb_name = rb_hash_aref(rb_data, CSTR2SYM("name"));
Check_Type(rb_name, T_STRING);
- rb_target = rb_hash_aref(rb_data, CSTR2SYM("target"));
- target = rugged_object_get(repo, rb_target, GIT_OBJ_ANY);
-
rb_force = rb_hash_aref(rb_data, CSTR2SYM("force"));
if (!NIL_P(rb_force))
force = rugged_parse_bool(rb_force);
/* only for heavy tags */
- rb_message = rb_hash_aref(rb_data, CSTR2SYM("message"));
rb_tagger = rb_hash_aref(rb_data, CSTR2SYM("tagger"));
+ rb_message = rb_hash_aref(rb_data, CSTR2SYM("message"));
+
+ if (!NIL_P(rb_message))
+ Check_Type(rb_message, T_STRING);
+
+ rb_target = rb_hash_aref(rb_data, CSTR2SYM("target"));
+ target = rugged_object_get(repo, rb_target, GIT_OBJ_ANY);
if (!NIL_P(rb_tagger) && !NIL_P(rb_message)) {
git_signature *tagger = NULL;
tagger = rugged_signature_get(rb_tagger);
- Check_Type(rb_message, T_STRING);
error = git_tag_create(
&tag_oid,
View
@@ -26,3 +26,43 @@ def test_reading_the_oid_of_a_tag
assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", obj.target_oid
end
end
+
+class TagWriteTest < Rugged::TestCase
+ include Rugged::TempRepositoryAccess
+
+ def test_writing_a_tag
+ person = {:name => 'Scott', :email => 'schacon@gmail.com', :time => Time.now }
+ tag_oid = Rugged::Tag.create(@repo,
+ :name => 'tag',
+ :message => "test tag message\n",
+ :target => "5b5b025afb0b4c913b4c338a42934a3863bf3644",
+ :tagger => person)
+
+ tag = @repo.lookup(tag_oid)
+ assert_equal :tag, tag.type
+ assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", tag.target.oid
+ assert_equal "test tag message\n", tag.message
+ assert_equal "Scott", tag.tagger[:name]
+ assert_equal "schacon@gmail.com", tag.tagger[:email]
+ end
+
+ def test_tag_invalid_message_type
+ person = {:name => 'Scott', :email => 'schacon@gmail.com', :time => Time.now }
+ assert_raises TypeError do
+ Rugged::Tag.create(@repo,
+ :name => 'tag',
+ :message => :invalid_message,
+ :target => "5b5b025afb0b4c913b4c338a42934a3863bf3644",
+ :tagger => person)
+ end
+ end
+
+ def test_writing_light_tags
+ Rugged::Tag.create(@repo,
+ :name => 'tag',
+ :target => "5b5b025afb0b4c913b4c338a42934a3863bf3644")
+
+ tag = Rugged::Reference.lookup(@repo, "refs/tags/tag")
+ assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", tag.target
+ end
+end

0 comments on commit b1a6ae2

Please sign in to comment.