diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2020-04-05 11:07:54 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2020-11-25 11:42:03 +0000 |
commit | cb4bfbc99dffa7679f42cf8500931fa250bb7db3 (patch) | |
tree | b3321a749eeba776074824d04f49fb47ddf978c1 /src/buffer.c | |
parent | a6dd58659d16207ec92a1f4d87ec620236ce4a23 (diff) | |
download | libgit2-cb4bfbc99dffa7679f42cf8500931fa250bb7db3.tar.gz |
buffer: git_buf_sanitize should return a value
`git_buf_sanitize` is called with user-input, and wants to sanity-check
that input. Allow it to return a value if the input was malformed in a
way that we cannot cope.
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/buffer.c b/src/buffer.c index f395a77cc..2928b1767 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -140,13 +140,17 @@ void git_buf_free(git_buf *buf) } #endif -void git_buf_sanitize(git_buf *buf) +int git_buf_sanitize(git_buf *buf) { if (buf->ptr == NULL) { - assert(buf->size == 0 && buf->asize == 0); + GIT_ASSERT_ARG(buf->size == 0 && buf->asize == 0); + buf->ptr = git_buf__initbuf; - } else if (buf->asize > buf->size) + } else if (buf->asize > buf->size) { buf->ptr[buf->size] = '\0'; + } + + return 0; } void git_buf_clear(git_buf *buf) |