{"thread":{"id":"5554","subject":"[PATCH 2/2] Handle invalid argc gently","startedAt":"2006-09-14T01:04:09Z","lastAt":"2006-09-14T18:25:39Z","messageCount":7,"participants":["Dmitry V. Levin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"26852","messageId":"20060914010409.GB20593@nomad.office.altlinux.org","threadId":"5554","inReplyTo":null,"subject":"[PATCH 2/2] Handle invalid argc gently","fromName":"Dmitry V. Levin","fromEmail":"ldv@altlinux.org","sentAt":"2006-09-14T01:04:09Z","receivedAt":"2006-09-14T01:04:09Z","isPatch":true,"sender":{"key":"ldv@altlinux.org","avatar":"https://avatars.githubusercontent.com/u/5281408?v=4"},"body":"describe, git: Handle argc==0 case the same way as argc==1.\nmerge-tree: Refuse excessive arguments.\n\nSigned-off-by: Dmitry V. Levin <ldv@altlinux.org>\n---\n describe.c   |    2 +-\n git.c        |    2 +-\n merge-tree.c |    2 +-\n 3 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/describe.c b/describe.c\nindex 5ed052d..2172e8f 100644\n--- a/describe.c\n+++ b/describe.c\n@@ -163,7 +163,7 @@ int main(int argc, char **argv)\n \n \tsetup_git_directory();\n \n-\tif (i == argc)\n+\tif (i >= argc)\n \t\tdescribe(\"HEAD\", 1);\n \telse\n \t\twhile (i < argc) {\ndiff --git a/git.c b/git.c\nindex 47c85e1..8c182a5 100644\n--- a/git.c\n+++ b/git.c\n@@ -294,7 +294,7 @@ static void handle_internal_command(int \n \n int main(int argc, const char **argv, char **envp)\n {\n-\tconst char *cmd = argv[0];\n+\tconst char *cmd = argv[0] ? argv[0] : \"git-help\";\n \tchar *slash = strrchr(cmd, '/');\n \tconst char *exec_path = NULL;\n \tint done_alias = 0;\ndiff --git a/merge-tree.c b/merge-tree.c\nindex c154dcf..692ede0 100644\n--- a/merge-tree.c\n+++ b/merge-tree.c\n@@ -337,7 +337,7 @@ int main(int argc, char **argv)\n \tstruct tree_desc t[3];\n \tvoid *buf1, *buf2, *buf3;\n \n-\tif (argc < 4)\n+\tif (argc != 4)\n \t\tusage(merge_tree_usage);\n \n \tsetup_git_directory();\n\n\n-- \nldv\n"},{"id":"26855","messageId":"7vu03b5k0t.fsf@assigned-by-dhcp.cox.net","threadId":"5554","inReplyTo":"20060914010409.GB20593@nomad.office.altlinux.org","subject":"Re: [PATCH 2/2] Handle invalid argc gently","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-09-14T01:12:02Z","receivedAt":"2006-09-14T01:12:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Dmitry V. Levin\" <ldv@altlinux.org> writes:\n\n> describe, git: Handle argc==0 case the same way as argc==1.\n\nWhen does one get (ac == 0)?\n"},{"id":"26856","messageId":"20060914013146.GD7044@basalt.office.altlinux.org","threadId":"5554","inReplyTo":"7vu03b5k0t.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 2/2] Handle invalid argc gently","fromName":"Dmitry V. Levin","fromEmail":"ldv@altlinux.org","sentAt":"2006-09-14T01:31:46Z","receivedAt":"2006-09-14T01:31:46Z","isPatch":true,"sender":{"key":"ldv@altlinux.org","avatar":"https://avatars.githubusercontent.com/u/5281408?v=4"},"body":"On Wed, Sep 13, 2006 at 06:12:02PM -0700, Junio C Hamano wrote:\n> \"Dmitry V. Levin\" <ldv@altlinux.org> writes:\n> \n> > describe, git: Handle argc==0 case the same way as argc==1.\n> \n> When does one get (ac == 0)?\n\nWhen one executes something like\nexeclp(\"git\", NULL, NULL);\n\n\n-- \nldv\n"},{"id":"26871","messageId":"7vpsdz5542.fsf@assigned-by-dhcp.cox.net","threadId":"5554","inReplyTo":"20060914013146.GD7044@basalt.office.altlinux.org","subject":"Re: [PATCH 2/2] Handle invalid argc gently","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-09-14T06:34:05Z","receivedAt":"2006-09-14T06:34:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Dmitry V. Levin\" <ldv@altlinux.org> writes:\n\n> On Wed, Sep 13, 2006 at 06:12:02PM -0700, Junio C Hamano wrote:\n>> \"Dmitry V. Levin\" <ldv@altlinux.org> writes:\n>> \n>> > describe, git: Handle argc==0 case the same way as argc==1.\n>> \n>> When does one get (ac == 0)?\n>\n> When one executes something like\n> execlp(\"git\", NULL, NULL);\n\nFair enough.\n\nWhat is the valid reason to do execlp(\"git\", NULL, NULL)?\n"},{"id":"26882","messageId":"20060914131626.GE6709@basalt.office.altlinux.org","threadId":"5554","inReplyTo":"7vpsdz5542.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 2/2] Handle invalid argc gently","fromName":"Dmitry V. Levin","fromEmail":"ldv@altlinux.org","sentAt":"2006-09-14T13:16:26Z","receivedAt":"2006-09-14T13:16:26Z","isPatch":true,"sender":{"key":"ldv@altlinux.org","avatar":"https://avatars.githubusercontent.com/u/5281408?v=4"},"body":"On Wed, Sep 13, 2006 at 11:34:05PM -0700, Junio C Hamano wrote:\n> \"Dmitry V. Levin\" <ldv@altlinux.org> writes:\n> > On Wed, Sep 13, 2006 at 06:12:02PM -0700, Junio C Hamano wrote:\n> >> \"Dmitry V. Levin\" <ldv@altlinux.org> writes:\n> >> \n> >> > describe, git: Handle argc==0 case the same way as argc==1.\n> >> \n> >> When does one get (ac == 0)?\n> >\n> > When one executes something like\n> > execlp(\"git\", NULL, NULL);\n> \n> Fair enough.\n> \n> What is the valid reason to do execlp(\"git\", NULL, NULL)?\n\nPersonally I do not plan to execute git this way on regular basis, indeed. :)\n\nBut argc == 0 is allowed, so why should git crash?\n\n\n-- \nldv\n"},{"id":"26896","messageId":"7virjq4cfj.fsf@assigned-by-dhcp.cox.net","threadId":"5554","inReplyTo":"20060914131626.GE6709@basalt.office.altlinux.org","subject":"Re: [PATCH 2/2] Handle invalid argc gently","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-09-14T16:53:36Z","receivedAt":"2006-09-14T16:53:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Dmitry V. Levin\" <ldv@altlinux.org> writes:\n\n>> What is the valid reason to do execlp(\"git\", NULL, NULL)?\n>\n> Personally I do not plan to execute git this way on regular basis, indeed. :)\n>\n> But argc == 0 is allowed, so why should git crash?\n\nOh, no I was not arguing for making git crash.  I was just\ntrying to learn if there is a valid reason to choose to, or\ncommon misconfiguration that causes it to, run with ac == 0,\nsince I did not think of any.\n\nIt is good to be extra careful and defensive -- I just wanted to\nknow if there is more to it.\n"},{"id":"26907","messageId":"20060914182539.GA12109@basalt.office.altlinux.org","threadId":"5554","inReplyTo":"7virjq4cfj.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 2/2] Handle invalid argc gently","fromName":"Dmitry V. Levin","fromEmail":"ldv@altlinux.org","sentAt":"2006-09-14T18:25:39Z","receivedAt":"2006-09-14T18:25:39Z","isPatch":true,"sender":{"key":"ldv@altlinux.org","avatar":"https://avatars.githubusercontent.com/u/5281408?v=4"},"body":"On Thu, Sep 14, 2006 at 09:53:36AM -0700, Junio C Hamano wrote:\n[...]\n> >> What is the valid reason to do execlp(\"git\", NULL, NULL)?\n> >\n> > Personally I do not plan to execute git this way on regular basis, indeed. :)\n> >\n> > But argc == 0 is allowed, so why should git crash?\n> \n> Oh, no I was not arguing for making git crash.  I was just\n> trying to learn if there is a valid reason to choose to, or\n> common misconfiguration that causes it to, run with ac == 0,\n> since I did not think of any.\n\nWell, the execlp example is somewhat dragged in.\nMore common case is execvp:\n\nchar *argv[] = { NULL };\nexecvp(\"git\", argv);\n\nThe argv array may be empty for various reasons, e.g. pointer arithmetic\nmistakes.\n\n\n-- \nldv\n"}]}