Skip to content

Commit

Permalink
commit_tree(): refuse commit messages that contain NULs
Browse files Browse the repository at this point in the history
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 <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Dec 15, 2011
1 parent 13f8b72 commit 37576c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions t/t3900-i18n-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ test_expect_success 'no encoding header for base case' '
test z = "z$E"
'

test_expect_failure 'UTF-16 refused because of NULs' '
echo UTF-16 >F &&
git commit -a -F "$TEST_DIRECTORY"/t3900/UTF-16.txt
'


for H in ISO8859-1 eucJP ISO-2022-JP
do
test_expect_success "$H setup" '
Expand Down

0 comments on commit 37576c1

Please sign in to comment.