Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
6adcaab7
Commit
6adcaab7
authored
Jan 08, 2014
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle git_buf's from users more liberally
parent
32309b5d
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
53 additions
and
2 deletions
+53
-2
include/git2/blob.h
+1
-1
src/blob.c
+2
-0
src/buffer.c
+8
-0
src/buffer.h
+9
-0
tests/filter/blob.c
+32
-0
tests/resources/crlf/.gitted/objects/2c/9a868cfdf8e270d0ec68164433376c68fb1789
+0
-0
tests/resources/crlf/.gitted/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
+0
-0
tests/resources/crlf/.gitted/objects/ef/0dcd356d77221e9c27f4f3928ad28e80b87ceb
+0
-0
tests/resources/crlf/.gitted/refs/heads/master
+1
-1
No files found.
include/git2/blob.h
View file @
6adcaab7
...
...
@@ -84,7 +84,7 @@ GIT_EXTERN(git_repository *) git_blob_owner(const git_blob *blob);
* time.
*
* @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
);
...
...
src/blob.c
View file @
6adcaab7
...
...
@@ -347,6 +347,8 @@ int git_blob_filtered_content(
assert
(
blob
&&
path
&&
out
);
git_buf_sanitize
(
out
);
if
(
check_for_binary_data
&&
git_blob_is_binary
(
blob
))
return
0
;
...
...
src/buffer.c
View file @
6adcaab7
...
...
@@ -100,6 +100,14 @@ void git_buf_free(git_buf *buf)
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
)
{
buf
->
size
=
0
;
...
...
src/buffer.h
View file @
6adcaab7
...
...
@@ -51,6 +51,15 @@ extern void git_buf_init(git_buf *buf, size_t initial_size);
extern
int
git_buf_try_grow
(
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
char
*
git_buf_detach
(
git_buf
*
buf
);
extern
void
git_buf_attach
(
git_buf
*
buf
,
char
*
ptr
,
size_t
asize
);
...
...
tests/filter/blob.c
View file @
6adcaab7
...
...
@@ -47,6 +47,38 @@ void test_filter_blob__all_crlf(void)
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
)
{
git_oid
id
;
...
...
tests/resources/crlf/.gitted/objects/2c/9a868cfdf8e270d0ec68164433376c68fb1789
0 → 100644
View file @
6adcaab7
File added
tests/resources/crlf/.gitted/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
0 → 100644
View file @
6adcaab7
File added
tests/resources/crlf/.gitted/objects/ef/0dcd356d77221e9c27f4f3928ad28e80b87ceb
0 → 100644
View file @
6adcaab7
File added
tests/resources/crlf/.gitted/refs/heads/master
View file @
6adcaab7
12faf3c1ea55f572473cec9052fca468c3584ccb
2c9a868cfdf8e270d0ec68164433376c68fb1789
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment