From 13f8b72d8c8e24215a3dd7771592b30083f1c740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 15 Dec 2011 20:47:22 +0700 Subject: Convert commit_tree() to take strbuf as message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There wan't a way for commit_tree() to notice if the message the caller prepared contained a NUL byte, as it did not take the length of the message as a parameter. Use a pointer to a strbuf instead, so that we can either choose to allow low-level plumbing commands to make commits that contain NUL byte in its message, or forbid NUL everywhere by adding the check in commit_tree(), in later patches. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- commit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'commit.c') diff --git a/commit.c b/commit.c index 73b7e0029..0a214a649 100644 --- a/commit.c +++ b/commit.c @@ -845,7 +845,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(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) { @@ -884,7 +884,7 @@ int commit_tree(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)) -- cgit v1.2.1 From 37576c14439a4dfa43bec5a5c953fea1cc436bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 15 Dec 2011 20:47:23 +0700 Subject: commit_tree(): refuse commit messages that contain NULs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current implementation sees NUL as terminator. If users give a message with NUL byte in it (e.g. editor set to save as UTF-16), the new commit message will have NULs. However following operations (displaying or amending a commit for example) will not keep anything after the first NUL. Stop user right when they do this. If NUL is added by mistake, they have their chance to fix. Otherwise, log messages will no longer be text "git log" and friends would grok. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- commit.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'commit.c') diff --git a/commit.c b/commit.c index 0a214a649..80e61b4cf 100644 --- a/commit.c +++ b/commit.c @@ -855,6 +855,9 @@ int commit_tree(const struct strbuf *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); -- cgit v1.2.1