diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2015-06-23 16:41:58 +0300 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-06-25 00:49:10 +0300 |
commit | caab22c0d468e90b6a95072f3092d5dcf331b3ef (patch) | |
tree | 158e761b2c5fea6fc651e8960c84fbb9fe307094 /tests/core | |
parent | aacfd03dba68333da726bb63e2594f3ed4a16422 (diff) |
buffer: don't allow growing borrowed buffers
When we don't own a buffer (asize=0) we currently allow the usage of
grow to copy the memory into a buffer we do own. This muddles the
meaning of grow, and lets us be a bit cavalier with ownership semantics.
Don't allow this any more. Usage of grow should be restricted to buffers
which we know own their own memory. If unsure, we must not attempt to
modify it.
Diffstat (limited to 'tests/core')
-rw-r--r-- | tests/core/buffer.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/core/buffer.c b/tests/core/buffer.c index fef37f8f7..cc2d7bbcc 100644 --- a/tests/core/buffer.c +++ b/tests/core/buffer.c @@ -1153,3 +1153,16 @@ void test_core_buffer__lf_and_crlf_conversions(void) git_buf_free(&src); git_buf_free(&tgt); } + +void test_core_buffer__dont_grow_borrowed(void) +{ + const char *somestring = "blah blah"; + git_buf buf = GIT_BUF_INIT; + + git_buf_attach_notowned(&buf, somestring, strlen(somestring) + 1); + cl_assert_equal_p(somestring, buf.ptr); + cl_assert_equal_i(0, buf.asize); + cl_assert_equal_i(strlen(somestring) + 1, buf.size); + + cl_git_fail_with(GIT_EINVALIDSPEC, git_buf_grow(&buf, 1024)); +} |