-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Handle git_buf's from users more liberally #2036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Sheesh. Has anybody else noticed that my verbosity in the PR comments is inversely proportional to the length of the pull request? |
@@ -84,7 +84,7 @@ | |||
* time. | |||
* | |||
* @param blob pointer to the blob | |||
* @return the pointer; NULL if the blob has no contents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right. I also updated this comment because it is not accurate!
Looks good to me. I'm a little on the fence if we should be checking the user input using an assert in this case or if we should be using a regular check with |
I assume we'll use this anywhere that we take a buf from the user that they are responsible for having initialized, which I guess means that the filter code doesn't need it now because the buffers in use there are always initialized by libgit2 internally, I believe. Does that seem right? |
Please reconsider the idea of forcing users to initialise |
@scunz The problem isn't What I meant was an actual |
This matches my thinking! |
My only concern is that will also require exposing |
Yeah. We could do it with |
Handle git_buf's from users more liberally
Looks very clean. Exporting |
Handle git_buf's from users more liberally
When accepting
git_buf
s as user input (ingit_blob_filtered_content
), we state that we accept agit_buf
that has aptr
value ofNULL
, but we in fact do not.From
buffer.h
:Thus, consumers tend to create a
git_buf
where all members are0
. See for examplegit_buf
creation in LibGit2Sharp and in jagged.However the
git_buf
family of functions were written thinking thatgit_buf
s would be initialized withGIT_BUF_INIT
orgit_buf_init
, namely that theptr
would always be null-terminated (set togit_buf__initbuf
), even whenasize
was 0. Indeed, this is documented inbuffer.c
:For example
git_buf_shorten
will always null-terminate. Ongit_buf
s provided from LibGit2Sharp or jagged, this will obviously try to dereference a null pointer.This basically brings this function in line with the documentation (we accept
NULL
, converting that internally to agit_buf__initbuf
). Obviously we could make more aggressive changes here - we could ensure that users always creategit_buf
s with some sort ofinit
method, or we could drop the assumption thatgit_buf
s are always null terminated, but those both seem unnecessary and this seems to me like a good middle ground.