git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Jens Lehmann" <Jens.Lehmann@web.de>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] submodule.c: duplicate real_path's return value
Date: Tue, 23 Apr 2013 21:00:02 +1000	[thread overview]
Message-ID: <1366714802-12010-1-git-send-email-pclouds@gmail.com> (raw)

real_path returns the pointer to an internal buffer, which may be
overwritten by the next real_path call. Duplicate the return value for
safety.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Apply on top of jl/submodule-mv.
 
 Junio, I think this is the reason some tests failed when you merged
 nd/magic-pathspecs in (I suspect you needed to do parse_pathspec
 call, which may do real_path internaly).

 I think "bug" fix like this should go in early, hence this patch. I'm
 going to rebase nd/magic-pathspecs after this series graduates to
 master anyway, feel free to reject.

 submodule.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/submodule.c b/submodule.c
index 6b01a02..9f442d8 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1102,7 +1102,8 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
 	struct strbuf configfile_name = STRBUF_INIT;
 	struct strbuf gitfile_content = STRBUF_INIT;
 	struct strbuf gitfile_name = STRBUF_INIT;
-	const char *real_work_tree = real_path(work_tree);
+	char *real_work_tree = xstrdup(real_path(work_tree));
+	char *to_free = real_work_tree;
 	const char *pathspec[] = { real_work_tree, git_dir, NULL };
 	const char *max_prefix = common_prefix(pathspec);
 	FILE *fp;
@@ -1157,4 +1158,5 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
 
 	strbuf_release(&core_worktree_setting);
 	strbuf_release(&configfile_name);
+	free(to_free);
 }
-- 
1.8.2.82.gc24b958

                 reply	other threads:[~2013-04-23 11:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1366714802-12010-1-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=Jens.Lehmann@web.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).