git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: Alex Riesen <raa.lkml@gmail.com>, Git Mailing List <git@vger.kernel.org>
Subject: [PATCH] Allow setup_work_tree() to be called several times
Date: Thu, 2 Aug 2007 23:04:13 +0100 (BST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0708022302360.14781@racer.site> (raw)
In-Reply-To: <7vk5sdtxx0.fsf@assigned-by-dhcp.cox.net>


setup_work_tree() used to rely on a static buffer being initialized to all 
zeroes.  While at it, unstatify a pointer.

Noticed by Alex Riesen.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

	On Thu, 2 Aug 2007, Junio C Hamano wrote:

	> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
	> 
	> >> 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?
	> >
	> > Apparently (but I would feel safer with strlcpy() anyway)...
	> 
	> Yup, send an appliable "final" version, somebody please?

	Here you are.

	> > ...  git-read-tree 
	> > is the first and only offender which comes up in the test suite:
	> 
	> It is unclear.
	> 
	> Is this an optimization, or enforcing the new world order?  IOW,
	> is it now banned to call setup twice?

	It is purely an optimization, because we allow calling setup twice 
	with this patch...  but we do not recommend it, as it is 
	unnecessary.

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

diff --git a/setup.c b/setup.c
index 3653092..16745f9 100644
--- a/setup.c
+++ b/setup.c
@@ -201,15 +201,15 @@ int is_inside_work_tree(void)
  */
 const char *set_work_tree(const char *dir)
 {
-	char dir_buffer[PATH_MAX];
-	static char buffer[PATH_MAX + 1], *rel = NULL;
+	char dir_buffer[PATH_MAX], *rel = NULL;
+	static char buffer[PATH_MAX + 1];
 	int len, postfix_len = strlen(DEFAULT_GIT_DIR_ENVIRONMENT) + 1;
 
 	/* strip the variable 'dir' of the postfix "/.git" if it has it */
 	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.121.g7f37

  reply	other threads:[~2007-08-02 22:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-02 15:25 [PATCH] Fix set_work_tree on cygwin Alex Riesen
2007-08-02 15:38 ` Johannes Schindelin
2007-08-02 20:49   ` Alex Riesen
2007-08-02 21:04     ` Johannes Schindelin
2007-08-02 21:14       ` Junio C Hamano
2007-08-02 21:36         ` Johannes Schindelin
2007-08-02 21:43           ` Junio C Hamano
2007-08-02 22:04             ` Johannes Schindelin [this message]
2007-08-02 22:02           ` [PATCH] Fix unterminated string copy in set_work_tree Alex Riesen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0708022302360.14781@racer.site \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=raa.lkml@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).