Skip to contentSkip to conversation

setup_git_directory_gently: fix off-by-one error

PATCH New Matthias Lederhofer 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 setup_git_directory_gently: fix off-by-one error

don't tell getcwd that the buffer has one spare byte for an extra /

---
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(-)
setup.c +1 -1
index dda67d2..a45ea83 100644
@@ -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);
Signature · 1 line
1.5.0.3