From caab22c0d468e90b6a95072f3092d5dcf331b3ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 23 Jun 2015 15:41:58 +0200 Subject: buffer: don't allow growing borrowed buffers When we don't own a buffer (asize=0) we currently allow the usage of grow to copy the memory into a buffer we do own. This muddles the meaning of grow, and lets us be a bit cavalier with ownership semantics. Don't allow this any more. Usage of grow should be restricted to buffers which we know own their own memory. If unsure, we must not attempt to modify it. --- src/path.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/path.c') diff --git a/src/path.c b/src/path.c index c2c90e48d..2558058dd 100644 --- a/src/path.c +++ b/src/path.c @@ -640,7 +640,7 @@ static bool _check_dir_contents( /* leave base valid even if we could not make space for subdir */ if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, dir_size, sub_size) || GIT_ADD_SIZET_OVERFLOW(&alloc_size, alloc_size, 2) || - git_buf_try_grow(dir, alloc_size, false, false) < 0) + git_buf_try_grow(dir, alloc_size, false) < 0) return false; /* save excursion */ @@ -847,7 +847,7 @@ int git_path_make_relative(git_buf *path, const char *parent) /* save the offset as we might realllocate the pointer */ offset = p - path->ptr; - if (git_buf_try_grow(path, alloclen, 1, 0) < 0) + if (git_buf_try_grow(path, alloclen, 1) < 0) return -1; p = path->ptr + offset; -- cgit v1.2.1