summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-12-22 19:27:26 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-12-22 19:27:26 (GMT)
commitf35ccd9be2db9a55afd09ed1a9338c758fa63d82 (patch)
treec94f3c518cdadb2c478e066547f152d3c753fb36 /commit.c
parent52b9d2cf7fbde061bf0d3336e3a89d7333d5b23d (diff)
parent37576c14439a4dfa43bec5a5c953fea1cc436bbf (diff)
downloadgit-f35ccd9be2db9a55afd09ed1a9338c758fa63d82.zip
git-f35ccd9be2db9a55afd09ed1a9338c758fa63d82.tar.gz
git-f35ccd9be2db9a55afd09ed1a9338c758fa63d82.tar.bz2
Merge branch 'nd/war-on-nul-in-commit'
* nd/war-on-nul-in-commit: commit_tree(): refuse commit messages that contain NULs Convert commit_tree() to take strbuf as message merge: abort if fails to commit Conflicts: builtin/commit.c commit.c commit.h
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/commit.c b/commit.c
index b781274..44bc96d 100644
--- a/commit.c
+++ b/commit.c
@@ -973,7 +973,7 @@ void free_commit_extra_headers(struct commit_extra_header *extra)
}
}
-int commit_tree(const char *msg, unsigned char *tree,
+int commit_tree(const struct strbuf *msg, unsigned char *tree,
struct commit_list *parents, unsigned char *ret,
const char *author)
{
@@ -991,7 +991,7 @@ static const char commit_utf8_warn[] =
"You may want to amend it after fixing the message, or set the config\n"
"variable i18n.commitencoding to the encoding your project uses.\n";
-int commit_tree_extended(const char *msg, unsigned char *tree,
+int commit_tree_extended(const struct strbuf *msg, unsigned char *tree,
struct commit_list *parents, unsigned char *ret,
const char *author, struct commit_extra_header *extra)
{
@@ -1001,6 +1001,9 @@ int commit_tree_extended(const char *msg, unsigned char *tree,
assert_sha1_type(tree, OBJ_TREE);
+ if (memchr(msg->buf, '\0', msg->len))
+ return error("a NUL byte in commit log message not allowed.");
+
/* Not having i18n.commitencoding is the same as having utf-8 */
encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
@@ -1037,7 +1040,7 @@ int commit_tree_extended(const char *msg, unsigned char *tree,
strbuf_addch(&buffer, '\n');
/* And add the comment */
- strbuf_addstr(&buffer, msg);
+ strbuf_addbuf(&buffer, msg);
/* And check the encoding */
if (encoding_is_utf8 && !is_utf8(buffer.buf))