From: Alex Riesen <raa.lkml@gmail.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Junio C Hamano <gitster@pobox.com>,
Git Mailing List <git@vger.kernel.org>
Subject: [PATCH] Fix unterminated string copy in set_work_tree
Date: Fri, 3 Aug 2007 00:02:55 +0200 [thread overview]
Message-ID: <20070802220255.GB2829@steel.home> (raw)
In-Reply-To: <Pine.LNX.4.64.0708022230070.14781@racer.site>
Use strlcpy which zero-terminates the output string
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
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
prev parent reply other threads:[~2007-08-02 22:03 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 ` [PATCH] Allow setup_work_tree() to be called several times Johannes Schindelin
2007-08-02 22:02 ` Alex Riesen [this message]
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=20070802220255.GB2829@steel.home \
--to=raa.lkml@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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).