git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] setup_git_directory_gently: fix off-by-one error

From
MLMatthias Lederhofer <matled@gmx.net>
Date
Mar 11, 2007, 01:35 UTC
Message-ID
<20070311013459.GA30057@moooo.ath.cx>
don't tell getcwd that the buffer has one spare byte for an extra /
Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
gdb session with PATH_MAX set to 2048:
Breakpoint 5, setup_git_directory_gently (nongit_ok=0x0) at
setup.c:253
253             cwd[len] = 0;
$ print sizeof(cwd)
$14 = 2049
$ print len
$15 = 2049
$ print PATH_MAX
$16 = 2048
---
 setup.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/setup.c b/setup.c
index dda67d2..a45ea83 100644
--- a/setup.c
+++ b/setup.c
@@ -216,7 +216,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
 		die("Not a git repository: '%s'", gitdirenv);
 	}
 
-	if (!getcwd(cwd, sizeof(cwd)) || cwd[0] != '/')
+	if (!getcwd(cwd, sizeof(cwd)-1) || cwd[0] != '/')
 		die("Unable to read current working directory");
 
 	offset = len = strlen(cwd);
-- 
1.5.0.3
Message 1 of 1 in “setup_git_directory_gently: fix off-by-one error”
  1. setup_git_directory_gently: fix off-by-one errorMatthias Lederhofer, Mar 11, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.