summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2014-01-08 10:07:30 -0800
committerEdward Thomson <ethomson@microsoft.com>2014-01-08 10:08:23 -0800
commit6adcaab70cdd6ced307a71945a1f80833ec9670f (patch)
tree4d10a5a2d7aa1cc16299c1bbcb006b371f8f8129 /src
parent32309b5d82d95402852cfcd478abec5d116eba86 (diff)
downloadlibgit2-6adcaab70cdd6ced307a71945a1f80833ec9670f.tar.gz
Handle git_buf's from users more liberally
Diffstat (limited to 'src')
-rw-r--r--src/blob.c2
-rw-r--r--src/buffer.c8
-rw-r--r--src/buffer.h9
3 files changed, 19 insertions, 0 deletions
diff --git a/src/blob.c b/src/blob.c
index ab344ae98..2e924f37f 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -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;
diff --git a/src/buffer.c b/src/buffer.c
index 20682322e..3283c2d4f 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -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;
diff --git a/src/buffer.h b/src/buffer.h
index c88af6fef..564a4f561 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -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);