summaryrefslogtreecommitdiff
path: root/tests/object
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-05-08 10:17:14 -0700
committerRussell Belfer <rb@github.com>2014-05-08 10:17:14 -0700
commit1e4976cb015bd10a2a8c377e02801306473afc26 (patch)
tree73cde51de2a436cdffa825b155c6888df41671bd /tests/object
parented476c236b8328c31acb150ee69eaf00c821b9e3 (diff)
downloadlibgit2-1e4976cb015bd10a2a8c377e02801306473afc26.tar.gz
Be more careful with user-supplied buffersrb/fix-2333
This adds in missing calls to `git_buf_sanitize` and fixes a number of places where `git_buf` APIs could inadvertently write NUL terminator bytes into invalid buffers. This also changes the behavior of `git_buf_sanitize` to NUL terminate a buffer if it can and of `git_buf_shorten` to do nothing if it can. Adds tests of filtering code with zeroed (i.e. unsanitized) buffer which was previously triggering a segfault.
Diffstat (limited to 'tests/object')
-rw-r--r--tests/object/blob/filter.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/tests/object/blob/filter.c b/tests/object/blob/filter.c
index 0b2d6bf9e..3cc8fdc3d 100644
--- a/tests/object/blob/filter.c
+++ b/tests/object/blob/filter.c
@@ -112,7 +112,7 @@ void test_object_blob_filter__to_odb(void)
git_config *cfg;
int i;
git_blob *blob;
- git_buf out = GIT_BUF_INIT;
+ git_buf out = GIT_BUF_INIT, zeroed;
cl_git_pass(git_repository_config(&cfg, g_repo));
cl_assert(cfg);
@@ -127,13 +127,20 @@ void test_object_blob_filter__to_odb(void)
for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) {
cl_git_pass(git_blob_lookup(&blob, g_repo, &g_crlf_oids[i]));
+ /* try once with allocated blob */
cl_git_pass(git_filter_list_apply_to_blob(&out, fl, blob));
-
cl_assert_equal_sz(g_crlf_filtered[i].size, out.size);
-
cl_assert_equal_i(
0, memcmp(out.ptr, g_crlf_filtered[i].ptr, out.size));
+ /* try again with zeroed blob */
+ memset(&zeroed, 0, sizeof(zeroed));
+ cl_git_pass(git_filter_list_apply_to_blob(&zeroed, fl, blob));
+ cl_assert_equal_sz(g_crlf_filtered[i].size, zeroed.size);
+ cl_assert_equal_i(
+ 0, memcmp(zeroed.ptr, g_crlf_filtered[i].ptr, zeroed.size));
+ git_buf_free(&zeroed);
+
git_blob_free(blob);
}