Commit 4f0e5f70 by Patrick Steinhardt

commit: fix reading out of bounds when parsing encoding

The commit message encoding is currently being parsed by the
`git__prefixcmp` function. As this function does not accept a buffer
length, it will happily skip over a buffer's end if it is not `NUL`
terminated.

Fix the issue by using `git__prefixncmp` instead. Add a test that
verifies that we are unable to parse the encoding field if it's cut off
by the supplied buffer length.

(cherry picked from commit 7655b2d8)
parent 6e40bb3a
......@@ -443,7 +443,7 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj)
while (eoln < buffer_end && *eoln != '\n')
++eoln;
if (git__prefixcmp(buffer, "encoding ") == 0) {
if (git__prefixncmp(buffer, buffer_end - buffer, "encoding ") == 0) {
buffer += strlen("encoding ");
commit->message_encoding = git__strndup(buffer, eoln - buffer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment