mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 18:22:16 +00:00
Merge pull request #2036 from ethomson/git_buf_sanitize
Handle git_buf's from users more liberally
This commit is contained in:
commit
cc3d961bd9
@ -84,7 +84,7 @@ GIT_EXTERN(git_repository *) git_blob_owner(const git_blob *blob);
|
|||||||
* time.
|
* time.
|
||||||
*
|
*
|
||||||
* @param blob pointer to the blob
|
* @param blob pointer to the blob
|
||||||
* @return the pointer; NULL if the blob has no contents
|
* @return the pointer
|
||||||
*/
|
*/
|
||||||
GIT_EXTERN(const void *) git_blob_rawcontent(const git_blob *blob);
|
GIT_EXTERN(const void *) git_blob_rawcontent(const git_blob *blob);
|
||||||
|
|
||||||
|
@ -347,6 +347,8 @@ int git_blob_filtered_content(
|
|||||||
|
|
||||||
assert(blob && path && out);
|
assert(blob && path && out);
|
||||||
|
|
||||||
|
git_buf_sanitize(out);
|
||||||
|
|
||||||
if (check_for_binary_data && git_blob_is_binary(blob))
|
if (check_for_binary_data && git_blob_is_binary(blob))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -100,6 +100,14 @@ void git_buf_free(git_buf *buf)
|
|||||||
git_buf_init(buf, 0);
|
git_buf_init(buf, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void git_buf_sanitize(git_buf *buf)
|
||||||
|
{
|
||||||
|
if (buf->ptr == NULL) {
|
||||||
|
assert (buf->size == 0 && buf->asize == 0);
|
||||||
|
buf->ptr = git_buf__initbuf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void git_buf_clear(git_buf *buf)
|
void git_buf_clear(git_buf *buf)
|
||||||
{
|
{
|
||||||
buf->size = 0;
|
buf->size = 0;
|
||||||
|
@ -51,6 +51,15 @@ extern void git_buf_init(git_buf *buf, size_t initial_size);
|
|||||||
extern int git_buf_try_grow(
|
extern int git_buf_try_grow(
|
||||||
git_buf *buf, size_t target_size, bool mark_oom, bool preserve_external);
|
git_buf *buf, size_t target_size, bool mark_oom, bool preserve_external);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitizes git_buf structures provided from user input. Users of the
|
||||||
|
* library, when providing git_buf's, may wish to provide a NULL ptr for
|
||||||
|
* ease of handling. The buffer routines, however, expect a non-NULL ptr
|
||||||
|
* always. This helper method simply handles NULL input, converting to a
|
||||||
|
* git_buf__initbuf.
|
||||||
|
*/
|
||||||
|
extern void git_buf_sanitize(git_buf *buf);
|
||||||
|
|
||||||
extern void git_buf_swap(git_buf *buf_a, git_buf *buf_b);
|
extern void git_buf_swap(git_buf *buf_a, git_buf *buf_b);
|
||||||
extern char *git_buf_detach(git_buf *buf);
|
extern char *git_buf_detach(git_buf *buf);
|
||||||
extern void git_buf_attach(git_buf *buf, char *ptr, size_t asize);
|
extern void git_buf_attach(git_buf *buf, char *ptr, size_t asize);
|
||||||
|
@ -47,6 +47,38 @@ void test_filter_blob__all_crlf(void)
|
|||||||
git_blob_free(blob);
|
git_blob_free(blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_filter_blob__sanitizes(void)
|
||||||
|
{
|
||||||
|
git_blob *blob;
|
||||||
|
git_buf buf;
|
||||||
|
|
||||||
|
cl_git_pass(git_revparse_single(
|
||||||
|
(git_object **)&blob, g_repo, "e69de29")); /* zero-byte */
|
||||||
|
|
||||||
|
cl_assert_equal_i(0, git_blob_rawsize(blob));
|
||||||
|
cl_assert_equal_s("", git_blob_rawcontent(blob));
|
||||||
|
|
||||||
|
memset(&buf, 0, sizeof(git_buf));
|
||||||
|
cl_git_pass(git_blob_filtered_content(&buf, blob, "file.bin", 1));
|
||||||
|
cl_assert_equal_sz(0, buf.size);
|
||||||
|
cl_assert_equal_s("", buf.ptr);
|
||||||
|
git_buf_free(&buf);
|
||||||
|
|
||||||
|
memset(&buf, 0, sizeof(git_buf));
|
||||||
|
cl_git_pass(git_blob_filtered_content(&buf, blob, "file.crlf", 1));
|
||||||
|
cl_assert_equal_sz(0, buf.size);
|
||||||
|
cl_assert_equal_s("", buf.ptr);
|
||||||
|
git_buf_free(&buf);
|
||||||
|
|
||||||
|
memset(&buf, 0, sizeof(git_buf));
|
||||||
|
cl_git_pass(git_blob_filtered_content(&buf, blob, "file.lf", 1));
|
||||||
|
cl_assert_equal_sz(0, buf.size);
|
||||||
|
cl_assert_equal_s("", buf.ptr);
|
||||||
|
git_buf_free(&buf);
|
||||||
|
|
||||||
|
git_blob_free(blob);
|
||||||
|
}
|
||||||
|
|
||||||
void test_filter_blob__ident(void)
|
void test_filter_blob__ident(void)
|
||||||
{
|
{
|
||||||
git_oid id;
|
git_oid id;
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user