{"thread":{"id":"36052","subject":"[PATCH] Setup.c: PATH_MAX is the length including the Nil","startedAt":"2014-03-04T16:29:10Z","lastAt":"2014-03-04T16:49:27Z","messageCount":2,"participants":["Sun He","Faiz Kothari"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"236005","messageId":"1393950550-9668-1-git-send-email-sunheehnus@gmail.com","threadId":"36052","inReplyTo":null,"subject":"[PATCH] Setup.c: PATH_MAX is the length including the Nil","fromName":"Sun He","fromEmail":"sunheehnus@gmail.com","sentAt":"2014-03-04T16:29:10Z","receivedAt":"2014-03-04T16:29:10Z","isPatch":true,"sender":{"key":"sunheehnus@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2889804?v=4"},"body":"Signed-off-by: Sun He <sunheehnus@gmail.com>\n---\n\nCheck the limit.h of linux and find out that the MACRO\n#define PATH_MAX        4096\t/* # chars in a path name including nul */\nSo if the magic number 40 is just the size it should be. (e.g. hash code)\nIt may bring bugs with the length(4056) of long name(gitdirenv).\nAs gitdirenv could be set by GIT_DIR_ENVIRONMENT.\nIf it is a bug, it will almost never occur.\nBut I need your help to know if there is the PATH_MAX of git is the mirror of the\nPATH_MAX of linux and if this fix is right?\nIf it was, there may be many places like \"PATH_MAX + 1\" could be replaced by\njust \"PATH_MAX\". And there may be many places like this.\n\nCheers,\nHe Sun\n\n setup.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/setup.c b/setup.c\nindex cffb6d6..1511612 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -395,7 +395,7 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,\n \tchar *gitfile;\n \tint offset;\n \n-\tif (PATH_MAX - 40 < strlen(gitdirenv))\n+\tif (PATH_MAX - 41 < strlen(gitdirenv))\n \t\tdie(\"'$%s' too big\", GIT_DIR_ENVIRONMENT);\n \n \tgitfile = (char*)read_gitfile(gitdirenv);\n-- \n1.9.0.138.g2de3478.dirty\n"},{"id":"236008","messageId":"CAFbjVc=bt4NX2uAPx98YCqEh_gKY=KVsm1iFHU8N86aqKL3VoQ@mail.gmail.com","threadId":"36052","inReplyTo":"1393950550-9668-1-git-send-email-sunheehnus@gmail.com","subject":"Re: [PATCH] Setup.c: PATH_MAX is the length including the Nil","fromName":"Faiz Kothari","fromEmail":"faiz.off93@gmail.com","sentAt":"2014-03-04T16:49:27Z","receivedAt":"2014-03-04T16:49:27Z","isPatch":true,"sender":{"key":"faiz.off93@gmail.com","avatar":null},"body":"On Tue, Mar 4, 2014 at 9:59 PM, Sun He <sunheehnus@gmail.com> wrote:\n> Signed-off-by: Sun He <sunheehnus@gmail.com>\n> ---\n>\n> Check the limit.h of linux and find out that the MACRO\n> #define PATH_MAX        4096    /* # chars in a path name including nul */\n> So if the magic number 40 is just the size it should be. (e.g. hash code)\n> It may bring bugs with the length(4056) of long name(gitdirenv).\n> As gitdirenv could be set by GIT_DIR_ENVIRONMENT.\n> If it is a bug, it will almost never occur.\n> But I need your help to know if there is the PATH_MAX of git is the mirror of the\n> PATH_MAX of linux and if this fix is right?\n> If it was, there may be many places like \"PATH_MAX + 1\" could be replaced by\n> just \"PATH_MAX\". And there may be many places like this.\n>\n> Cheers,\n> He Sun\n\nHi,\nI am not getting what exactly you are trying to tell, but git defines\nits own PATH_MAX.\nIts defined in git-compat-util.h: #define PATH_MAX 4096\nThat is why instead of making buffers using PATH_MAX, use strbuf.\nAll these problems of buffer overflow will be gone.\nI hope you are concerned about buffer overflow.\n\nCheers\n\n-Faiz\n"}]}