[PATCH] alloc_ref(): allow for trailing NUL

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <gitster@...>, <git@...>
Date: Thursday, September 27, 2007 - 10:57 pm

The parameter name "namelen" suggests that you pass the equivalent of
strlen() to the function alloc_ref().  However, this function did not
allocate enough space to put a NUL after the name.

Since struct ref does not have any member to describe the length of the
string, this just does not make sense.

So make space for the NUL.

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

diff --git a/remote.c b/remote.c
index e7d735b..7531c92 100644
--- a/remote.c
+++ b/remote.c
@@ -453,7 +453,7 @@ int remote_find_tracking(struct remote *remote, struct refspec *refspec)
 
 struct ref *alloc_ref(unsigned namelen)
 {
-	struct ref *ret = xmalloc(sizeof(struct ref) + namelen);
+	struct ref *ret = xmalloc(sizeof(struct ref) + namelen + 1);
 	memset(ret, 0, sizeof(struct ref) + namelen);
 	return ret;
 }
-- 
1.5.3.2.1102.g9487

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] alloc_ref(): allow for trailing NUL, Johannes Schindelin, (Thu Sep 27, 10:57 pm)
Re: [PATCH] alloc_ref(): allow for trailing NUL, Daniel Barkalow, (Fri Sep 28, 1:03 am)
Re: [PATCH] alloc_ref(): allow for trailing NUL, Junio C Hamano, (Fri Sep 28, 4:46 am)
Re: [PATCH] alloc_ref(): allow for trailing NUL, Johannes Schindelin, (Fri Sep 28, 8:01 am)
Re: [PATCH] alloc_ref(): allow for trailing NUL, Daniel Barkalow, (Fri Sep 28, 11:44 am)
Re: [PATCH] alloc_ref(): allow for trailing NUL, Johannes Schindelin, (Fri Sep 28, 12:11 pm)
Re: [PATCH] alloc_ref(): allow for trailing NUL, Junio C Hamano, (Fri Sep 28, 2:08 pm)
Re: [PATCH] alloc_ref(): allow for trailing NUL, Pierre Habouzit, (Fri Sep 28, 8:41 am)
Re: [PATCH] alloc_ref(): allow for trailing NUL, Pierre Habouzit, (Fri Sep 28, 9:13 am)