{"thread":{"id":"41724","subject":"[PATCH v2] builtin/apply: exit when parse_binary() fails","startedAt":"2016-03-17T09:23:34Z","lastAt":"2016-03-17T09:34:25Z","messageCount":2,"participants":["Christian Couder"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"281016","messageId":"1458206614-2898-1-git-send-email-chriscool@tuxfamily.org","threadId":"41724","inReplyTo":null,"subject":"[PATCH v2] builtin/apply: exit when parse_binary() fails","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-03-17T09:23:34Z","receivedAt":"2016-03-17T09:23:34Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"In parse_binary() there is:\n\n\tforward = parse_binary_hunk(&buffer, &size, &status, &used);\n\tif (!forward && !status)\n\t\t/* there has to be one hunk (forward hunk) */\n\t\treturn error(_(\"unrecognized binary patch at line %d\"), linenr-1);\n\nso parse_binary() can return -1, because that's what error() returns.\n\nAlso parse_binary_hunk() sets \"status\" to -1 in case of error and\nparse_binary() does \"if (status) return status;\".\n\nIn this case parse_chunk() should not add -1 to the patchsize it computes.\nIt is better for future libification efforts to make it just return -1.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin/apply.c | 7 +++++++\n 1 file changed, 7 insertions(+)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 42c610e..c399c97 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -1872,6 +1872,11 @@ static struct fragment *parse_binary_hunk(char **buf_p,\n \treturn NULL;\n }\n \n+/*\n+ * Returns:\n+ *   -1 in case of error,\n+ *   the length of the parsed binary patch otherwise\n+ */\n static int parse_binary(char *buffer, unsigned long size, struct patch *patch)\n {\n \t/*\n@@ -2017,6 +2022,8 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)\n \t\t\tlinenr++;\n \t\t\tused = parse_binary(buffer + hd + llen,\n \t\t\t\t\t    size - hd - llen, patch);\n+\t\t\tif (used < 0)\n+\t\t\t\treturn -1;\n \t\t\tif (used)\n \t\t\t\tpatchsize = used + llen;\n \t\t\telse\n-- \n2.8.0.rc2.1.g21d258f\n"},{"id":"281017","messageId":"CAP8UFD2NgSfVVZrshimM+=7dFmhjqGmUVsTymgoQOXvhegr_1g@mail.gmail.com","threadId":"41724","inReplyTo":"1458206614-2898-1-git-send-email-chriscool@tuxfamily.org","subject":"Re: [PATCH v2] builtin/apply: exit when parse_binary() fails","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-03-17T09:34:25Z","receivedAt":"2016-03-17T09:34:25Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Thu, Mar 17, 2016 at 10:23 AM, Christian Couder\n<christian.couder@gmail.com> wrote:\n> In parse_binary() there is:\n...\n\nOf course just after sending this I realized that I should probably\nchange the title of the patch to something like \"builtin/apply: handle\nparse_binary() failure\".\n\nI will resend a v3 with the above change later...\n"}]}