{"thread":{"id":"46301","subject":"[PATCH] apply: use starts_with() in gitdiff_verify_name()","startedAt":"2017-07-01T09:10:39Z","lastAt":"2017-07-01T09:10:39Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"323669","messageId":"185fd8c0-e0bf-2522-77e3-3f9fce8a5d44@web.de","threadId":"46301","inReplyTo":null,"subject":"[PATCH] apply: use starts_with() in gitdiff_verify_name()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-07-01T09:10:07Z","receivedAt":"2017-07-01T09:10:39Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Avoid running over the end of line -- a C string whose length is not\nknown to this function -- by using starts_with() instead of memcmp(3)\nfor checking if it starts with \"/dev/null\".  Also simply include the\nnewline in the string constant to compare against.  Drop a comment that\njust states the obvious.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n apply.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex c442b89328..946be4d2f5 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -976,8 +976,7 @@ static int gitdiff_verify_name(struct apply_state *state,\n \t\t}\n \t\tfree(another);\n \t} else {\n-\t\t/* expect \"/dev/null\" */\n-\t\tif (memcmp(\"/dev/null\", line, 9) || line[9] != '\\n')\n+\t\tif (!starts_with(line, \"/dev/null\\n\"))\n \t\t\treturn error(_(\"git apply: bad git-diff - expected /dev/null on line %d\"), state->linenr);\n \t}\n \n-- \n2.13.2\n"}]}