git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wang Hui <Hui.Wang@windriver.com>
To: <gitster@pobox.com>, <git@vger.kernel.org>
Subject: [PATCH] abspath: increase array size of cwd variable to PATH_MAX
Date: Mon, 19 Sep 2011 17:51:12 +0800	[thread overview]
Message-ID: <1316425872-30457-1-git-send-email-Hui.Wang@windriver.com> (raw)

From: Hui Wang <Hui.Wang@windriver.com>

If the name length of working dir exceeds 1024 characters, neither git
clone nor git init can succeed under the working dir.
E.G. %>for ((i=1;i<300;i++));do mkdir 1234567890;cd 1234567890;done
     %>git clone ~/git
     fatal: Could not get current working directory: Numerical result
     out of range

This is because both git clone and git init will call
abspath.c:real_path(), in the real_path(), it will call getcwd()
to get and save current working dir, here we passed a 1024 char size
array to the parameter, if the name length of current working dir
exceeds 1024, this function will fail.

The purpose of calling getcwd() is to save current working dir, then
before the real_path() return, restore to the saved dir. We should use
PATH_MAX instead of 1024 for the array size.

Signed-off-by: Hui Wang <Hui.Wang@windriver.com>
---
 abspath.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/abspath.c b/abspath.c
index f04ac18..2ce1db9 100644
--- a/abspath.c
+++ b/abspath.c
@@ -24,7 +24,7 @@ int is_directory(const char *path)
 const char *real_path(const char *path)
 {
 	static char bufs[2][PATH_MAX + 1], *buf = bufs[0], *next_buf = bufs[1];
-	char cwd[1024] = "";
+	char cwd[PATH_MAX] = "";
 	int buf_index = 1;
 
 	int depth = MAXDEPTH;
-- 
1.6.3.1

             reply	other threads:[~2011-09-19  9:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-19  9:51 Wang Hui [this message]
2011-09-19 16:43 ` [PATCH] abspath: increase array size of cwd variable to PATH_MAX Junio C Hamano
2011-09-20 22:57   ` Ramsay Jones
2011-09-21 20:17     ` Junio C Hamano
2011-09-22  8:54       ` wanghui
2011-09-22  2:09     ` wanghui

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=1316425872-30457-1-git-send-email-Hui.Wang@windriver.com \
    --to=hui.wang@windriver.com \
    --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).