# [PATCH 0/2] Fix two issues found by valgrind

4 messages from 2009-01-27 to 2009-01-27. Participants: Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/17401

## Johannes Schindelin, 2009-01-27 23:07

Subject: [PATCH 0/2] Fix two issues found by valgrind
Message-ID: <alpine.DEB.1.00.0901280005180.3586@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0901280005180.3586%40pacific.mpi-cbg.de

```
Okay, not tons of issues.  But at least it was worth the hassle.

Johannes Schindelin (2):
  test-path-utils: Fix off by one, found by valgrind
  get_sha1_basic(): fix invalid memory access, found by valgrind

 sha1_name.c       |    2 +-
 test-path-utils.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

```

## Johannes Schindelin, 2009-01-27 23:07

Subject: [PATCH 1/2] test-path-utils: Fix off by one, found by valgrind
Message-ID: <alpine.DEB.1.00.0901280007250.3586@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0901280007250.3586%40pacific.mpi-cbg.de
In-Reply-To: <alpine.DEB.1.00.0901280005180.3586@pacific.mpi-cbg.de>

```
When normalizing an absolute path, we might have to add a slash _and_ a
NUL to the buffer, so the buffer was one too small.

Let's just future proof the code and alloc PATH_MAX + 1 bytes.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 test-path-utils.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/test-path-utils.c b/test-path-utils.c
index a0bcb0e..2c0f5a3 100644
--- a/test-path-utils.c
+++ b/test-path-utils.c
@@ -3,7 +3,7 @@
 int main(int argc, char **argv)
 {
 	if (argc == 3 && !strcmp(argv[1], "normalize_absolute_path")) {
-		char *buf = xmalloc(strlen(argv[2])+1);
+		char *buf = xmalloc(PATH_MAX + 1);
 		int rv = normalize_absolute_path(buf, argv[2]);
 		assert(strlen(buf) == rv);
 		puts(buf);
-- 
1.6.1.482.g7d54be

```

## Johannes Schindelin, 2009-01-27 23:07

Subject: [PATCH 2/2] get_sha1_basic(): fix invalid memory access, found by valgrind
Message-ID: <alpine.DEB.1.00.0901280007400.3586@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0901280007400.3586%40pacific.mpi-cbg.de
In-Reply-To: <alpine.DEB.1.00.0901280005180.3586@pacific.mpi-cbg.de>

```
When get_sha1_basic() is passed a buffer of len 0, it should not
check if buf[len-1] is a curly bracket.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 sha1_name.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/sha1_name.c b/sha1_name.c
index 7d95bbb..5d0ac02 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -334,7 +334,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
 
 	/* basic@{time or number or -number} format to query ref-log */
 	reflog_len = at = 0;
-	if (str[len-1] == '}') {
+	if (len && str[len-1] == '}') {
 		for (at = len-2; at >= 0; at--) {
 			if (str[at] == '@' && str[at+1] == '{') {
 				reflog_len = (len-1) - (at+2);
-- 
1.6.1.482.g7d54be

```

## Junio C Hamano, 2009-01-27 23:17

Subject: Re: [PATCH 0/2] Fix two issues found by valgrind
Message-ID: <7v63k01gqn.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v63k01gqn.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <alpine.DEB.1.00.0901280005180.3586@pacific.mpi-cbg.de>

```
Johannes Schindelin <johannes.schindelin@gmx.de> writes:

> Okay, not tons of issues.  But at least it was worth the hassle.

Thanks.

```
