]> git.ipfire.org Git - thirdparty/git.git/commit - t/t4254-am-corrupt.sh
mailinfo.c: avoid strlen on strings that can contains NUL
authorĐoàn Trần Công Danh <congdanhqx@gmail.com>
Mon, 20 Apr 2020 23:54:35 +0000 (06:54 +0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 22 Apr 2020 21:01:02 +0000 (14:01 -0700)
commit2a2ff6039606b93ad08d8d377804ddcd0bc41312
tree1e44eb3de7c5ca3631ae16da67e7c2c65406e49c
parent2ed282cc0d541d665dc7561ff962566378328bd6
mailinfo.c: avoid strlen on strings that can contains NUL

We're passing buffer from strbuf to reencode_string,
which will call strlen(3) on that buffer,
and discard the length of newly created buffer.
Then, we compute the length of the return buffer to attach to strbuf.

During this process, we introduce a discrimination between mail
originally written in utf-8 and other encoding.

* if the email was written in utf-8, we leave it as is. If there is
  a NUL character in that line, we complains loudly:

   error: a NUL byte in commit log message not allowed.

* if the email was written in other encoding, we truncate the data as
  the NUL character in that line, then we used the truncated line for
  the metadata.

We can do better by reusing all the available information,
and call the underlying lower level function that will be called
indirectly by reencode_string. By doing this, we will also postpone
the NUL character processing to the commit step, which will
complains about the faulty metadata.

Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
mailinfo.c
t/t4254-am-corrupt.sh