[PATCH] Fix unterminated string copy in set_work_tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use strlcpy which zero-terminates the output string

Signed-off-by: Alex Riesen <raa.lkml@xxxxxxxxx>
---
Johannes Schindelin, Thu, Aug 02, 2007 23:36:37 +0200:
> On Thu, 2 Aug 2007, Junio C Hamano wrote:
> > 
> > Static is supposed to be zeroed and also is supposed to retain
> > the value from the previous call.  I am guessing from the change
> > to make "rel" to non-static that this function is called twice
> > perhaps?

Actually, I was very confused. When I wrote about cygwin problems,
I actually debugged it for dir_buffer, real stack-based variable,
which of course is not zero-initialized. For an unknown reason I
confused the variable with buffer, which is static. "rel" should
be left of this particular discussion (it just does not matter whether
it is static or not in this context).

So the fix is a real fix for real problem which just happens to be
invisible on our linux systems.

> Apparently (but I would feel safer with strlcpy() anyway).  git-read-tree 
> is the first and only offender which comes up in the test suite:

Yes, I feel so too, so here it is.

 setup.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/setup.c b/setup.c
index 3653092..27d585c 100644
--- a/setup.c
+++ b/setup.c
@@ -209,7 +209,7 @@ const char *set_work_tree(const char *dir)
 	len = strlen(dir);
 	if (len > postfix_len && !strcmp(dir + len - postfix_len,
 				"/" DEFAULT_GIT_DIR_ENVIRONMENT)) {
-			strncpy(dir_buffer, dir, len - postfix_len);
+		strlcpy(dir_buffer, dir, len - postfix_len + 1);
 
 		/* are we inside the default work tree? */
 		rel = get_relative_cwd(buffer, sizeof(buffer), dir_buffer);
-- 
1.5.3.rc3.139.ga57724


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux