{"thread":{"id":"7188","subject":"[PATCH] setup_git_directory_gently: fix off-by-one error","startedAt":"2007-03-11T01:35:00Z","lastAt":"2007-03-11T01:35:00Z","messageCount":1,"participants":["Matthias Lederhofer"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"36769","messageId":"20070311013459.GA30057@moooo.ath.cx","threadId":"7188","inReplyTo":null,"subject":"[PATCH] setup_git_directory_gently: fix off-by-one error","fromName":"Matthias Lederhofer","fromEmail":"matled@gmx.net","sentAt":"2007-03-11T01:35:00Z","receivedAt":"2007-03-11T01:35:00Z","isPatch":true,"sender":{"key":"matled@gmx.net","avatar":null},"body":"don't tell getcwd that the buffer has one spare byte for an extra /\n\nSigned-off-by: Matthias Lederhofer <matled@gmx.net>\n---\ngdb session with PATH_MAX set to 2048:\nBreakpoint 5, setup_git_directory_gently (nongit_ok=0x0) at\nsetup.c:253\n253             cwd[len] = 0;\n$ print sizeof(cwd)\n$14 = 2049\n$ print len\n$15 = 2049\n$ print PATH_MAX\n$16 = 2048\n---\n setup.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/setup.c b/setup.c\nindex dda67d2..a45ea83 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -216,7 +216,7 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\tdie(\"Not a git repository: '%s'\", gitdirenv);\n \t}\n \n-\tif (!getcwd(cwd, sizeof(cwd)) || cwd[0] != '/')\n+\tif (!getcwd(cwd, sizeof(cwd)-1) || cwd[0] != '/')\n \t\tdie(\"Unable to read current working directory\");\n \n \toffset = len = strlen(cwd);\n-- \n1.5.0.3\n"}]}