Skip to content

Commit 28d1820

Browse files
committed
Protect TagAnnotation creation from name or message containing '\0'
1 parent c8ba327 commit 28d1820

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

LibGit2Sharp.Tests/ObjectDatabaseFixture.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,5 +433,22 @@ public void CreatingACommitWithMessageContainingZeroByteThrows(string message)
433433
message, Constants.Signature, Constants.Signature, repo.Head.Tip.Tree, Enumerable.Empty<Commit>()));
434434
}
435435
}
436+
437+
[Theory]
438+
[InlineData("\0Leading zero")]
439+
[InlineData("Trailing zero\0")]
440+
[InlineData("Zero \0inside")]
441+
[InlineData("\0")]
442+
[InlineData("\0\0\0")]
443+
public void CreatingATagAnnotationWithNameOrMessageContainingZeroByteThrows(string input)
444+
{
445+
using (var repo = new Repository(BareTestRepoPath))
446+
{
447+
Assert.Throws<ArgumentException>(() => repo.ObjectDatabase.CreateTagAnnotation(
448+
input, repo.Head.Tip, Constants.Signature, "message"));
449+
Assert.Throws<ArgumentException>(() => repo.ObjectDatabase.CreateTagAnnotation(
450+
"name", repo.Head.Tip, Constants.Signature, input));
451+
}
452+
}
436453
}
437454
}

LibGit2Sharp/ObjectDatabase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ internal Commit CreateCommit(string message, Signature author, Signature committ
222222
/// <returns>The created <see cref="TagAnnotation"/>.</returns>
223223
public virtual TagAnnotation CreateTagAnnotation(string name, GitObject target, Signature tagger, string message)
224224
{
225+
Ensure.ArgumentDoesNotContainZeroByte(name, "name");
226+
Ensure.ArgumentDoesNotContainZeroByte(message, "message");
227+
225228
string prettifiedMessage = Proxy.git_message_prettify(message);
226229

227230
ObjectId tagId = Proxy.git_tag_annotation_create(repo.Handle, name, target, tagger, prettifiedMessage);

0 commit comments

Comments
 (0)