Skip to content

Commit 2fc423c

Browse files
author
Jiri Benc
committed
Use returned buffer size of git_buf
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
1 parent 8bcb35d commit 2fc423c

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/branch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Branch_remote_name__get__(Branch *self)
190190
if (err < GIT_OK)
191191
return Error_set(err);
192192

193-
py_name = to_unicode(name.ptr, NULL, NULL);
193+
py_name = to_unicode_n(name.ptr, name.size, NULL, NULL);
194194
git_buf_dispose(&name);
195195

196196
return py_name;
@@ -268,7 +268,7 @@ Branch_upstream_name__get__(Branch *self)
268268
if (err < GIT_OK)
269269
return Error_set(err);
270270

271-
py_name = to_unicode(name.ptr, NULL, NULL);
271+
py_name = to_unicode_n(name.ptr, name.size, NULL, NULL);
272272
git_buf_dispose(&name);
273273

274274
return py_name;

src/diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ Diff_patch__get__(Diff *self)
633633
git_patch_free(patch);
634634
}
635635

636-
py_patch = to_unicode(buf.ptr, NULL, NULL);
636+
py_patch = to_unicode_n(buf.ptr, buf.size, NULL, NULL);
637637
git_buf_dispose(&buf);
638638

639639
cleanup:
@@ -831,7 +831,7 @@ DiffStats_format(DiffStats *self, PyObject *args, PyObject *kwds)
831831
if (err < 0)
832832
return Error_set(err);
833833

834-
str = to_unicode(buf.ptr, NULL, NULL);
834+
str = to_unicode_n(buf.ptr, buf.size, NULL, NULL);
835835
git_buf_dispose(&buf);
836836

837837
return str;

src/options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ get_search_path(long level)
4545
if (err < 0)
4646
return Error_set(err);
4747

48-
py_path = to_unicode(buf.ptr, NULL, NULL);
48+
py_path = to_unicode_n(buf.ptr, buf.size, NULL, NULL);
4949
git_buf_dispose(&buf);
5050

5151
if (!py_path)

src/patch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Patch_text__get__(Patch *self)
207207
if (err < 0)
208208
return Error_set(err);
209209

210-
text = to_unicode(buf.ptr, NULL, NULL);
210+
text = to_unicode_n(buf.ptr, buf.size, NULL, NULL);
211211
git_buf_dispose(&buf);
212212
return text;
213213
}

0 commit comments

Comments
 (0)