{"thread":{"id":"36832","subject":"[PATCH] update-index: fix segfault with missing --cacheinfo argument","startedAt":"2014-06-04T07:11:11Z","lastAt":"2014-06-04T18:03:13Z","messageCount":2,"participants":["Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"243278","messageId":"20140604071110.GA22158@sigill.intra.peff.net","threadId":"36832","inReplyTo":null,"subject":"[PATCH] update-index: fix segfault with missing --cacheinfo argument","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-06-04T07:11:11Z","receivedAt":"2014-06-04T07:11:11Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"Running \"git update-index --cacheinfo\" without any further\narguments results in a segfault rather than an error\nmessage. Commit ec160ae (update-index: teach --cacheinfo a\nnew syntax \"mode,sha1,path\", 2014-03-23) added code to\nexamine the format of the argument, but forgot to handle the\nNULL case.\n\nReturning an error from the parser is enough, since we then\ntreat it as an old-style \"--cacheinfo <mode> <sha1> <path>\",\nand complain that we have less than 3 arguments to read.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n builtin/update-index.c        | 3 +++\n t/t2107-update-index-basic.sh | 4 ++++\n 2 files changed, 7 insertions(+)\n\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex ba54e19..ebea285 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -637,6 +637,9 @@ static int parse_new_style_cacheinfo(const char *arg,\n \tunsigned long ul;\n \tchar *endp;\n \n+\tif (!arg)\n+\t\treturn -1;\n+\n \terrno = 0;\n \tul = strtoul(arg, &endp, 8);\n \tif (errno || endp == arg || *endp != ',' || (unsigned int) ul != ul)\ndiff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.sh\nindex fe2fb17..1bafb90 100755\n--- a/t/t2107-update-index-basic.sh\n+++ b/t/t2107-update-index-basic.sh\n@@ -29,6 +29,10 @@ test_expect_success 'update-index -h with corrupt index' '\n \ttest_i18ngrep \"[Uu]sage: git update-index\" broken/usage\n '\n \n+test_expect_success '--cacheinfo complains of missing arguments' '\n+\ttest_must_fail git update-index --cacheinfo\n+'\n+\n test_expect_success '--cacheinfo does not accept blob null sha1' '\n \techo content >file &&\n \tgit add file &&\n-- \n2.0.0.rc1.436.g03cb729\n"},{"id":"243312","messageId":"xmqqioogv9ge.fsf@gitster.dls.corp.google.com","threadId":"36832","inReplyTo":"20140604071110.GA22158@sigill.intra.peff.net","subject":"Re: [PATCH] update-index: fix segfault with missing --cacheinfo argument","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-06-04T18:03:13Z","receivedAt":"2014-06-04T18:03:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Running \"git update-index --cacheinfo\" without any further\n> arguments results in a segfault rather than an error\n> message. Commit ec160ae (update-index: teach --cacheinfo a\n> new syntax \"mode,sha1,path\", 2014-03-23) added code to\n> examine the format of the argument, but forgot to handle the\n> NULL case.\n>\n> Returning an error from the parser is enough, since we then\n> treat it as an old-style \"--cacheinfo <mode> <sha1> <path>\",\n> and complain that we have less than 3 arguments to read.\n>\n> Signed-off-by: Jeff King <peff@peff.net>\n> ---\n\nThanks.\n"}]}