Skip to content

Commit

Permalink
Use returned buffer size of git_buf
Browse files Browse the repository at this point in the history
The returned string may contain a '\0' character. Although not common, it
can happen e.g. in the diff output. Instead of truncating the output on the
null character, use the returned size from git_buf.

Fixes #1043
  • Loading branch information
Jiri Benc committed Nov 10, 2020
1 parent 8bcb35d commit 2fc423c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Branch_remote_name__get__(Branch *self)
if (err < GIT_OK)
return Error_set(err);

py_name = to_unicode(name.ptr, NULL, NULL);
py_name = to_unicode_n(name.ptr, name.size, NULL, NULL);
git_buf_dispose(&name);

return py_name;
Expand Down Expand Up @@ -268,7 +268,7 @@ Branch_upstream_name__get__(Branch *self)
if (err < GIT_OK)
return Error_set(err);

py_name = to_unicode(name.ptr, NULL, NULL);
py_name = to_unicode_n(name.ptr, name.size, NULL, NULL);
git_buf_dispose(&name);

return py_name;
Expand Down
4 changes: 2 additions & 2 deletions src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ Diff_patch__get__(Diff *self)
git_patch_free(patch);
}

py_patch = to_unicode(buf.ptr, NULL, NULL);
py_patch = to_unicode_n(buf.ptr, buf.size, NULL, NULL);
git_buf_dispose(&buf);

cleanup:
Expand Down Expand Up @@ -831,7 +831,7 @@ DiffStats_format(DiffStats *self, PyObject *args, PyObject *kwds)
if (err < 0)
return Error_set(err);

str = to_unicode(buf.ptr, NULL, NULL);
str = to_unicode_n(buf.ptr, buf.size, NULL, NULL);
git_buf_dispose(&buf);

return str;
Expand Down
2 changes: 1 addition & 1 deletion src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ get_search_path(long level)
if (err < 0)
return Error_set(err);

py_path = to_unicode(buf.ptr, NULL, NULL);
py_path = to_unicode_n(buf.ptr, buf.size, NULL, NULL);
git_buf_dispose(&buf);

if (!py_path)
Expand Down
2 changes: 1 addition & 1 deletion src/patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ Patch_text__get__(Patch *self)
if (err < 0)
return Error_set(err);

text = to_unicode(buf.ptr, NULL, NULL);
text = to_unicode_n(buf.ptr, buf.size, NULL, NULL);
git_buf_dispose(&buf);
return text;
}
Expand Down

0 comments on commit 2fc423c

Please sign in to comment.