git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] abspath: increase array size of cwd variable to PATH_MAX
@ 2011-09-19  9:51 Wang Hui
  2011-09-19 16:43 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Wang Hui @ 2011-09-19  9:51 UTC (permalink / raw)
  To: gitster, git

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-09-22  8:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-19  9:51 [PATCH] abspath: increase array size of cwd variable to PATH_MAX Wang Hui
2011-09-19 16:43 ` 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

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).