{"thread":{"id":"7975","subject":"[PATCH] Small correction in reading of commit headers","startedAt":"2007-05-04T21:51:32Z","lastAt":"2007-05-04T21:51:32Z","messageCount":1,"participants":["Alex Riesen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"41095","messageId":"20070504215132.GD4033@steel.home","threadId":"7975","inReplyTo":null,"subject":"[PATCH] Small correction in reading of commit headers","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-05-04T21:51:32Z","receivedAt":"2007-05-04T21:51:32Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Check if a line of the header has enough characters to possibly\ncontain the requested prefix.\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\n\nNoticed by debugging git-log crash in broken repos with\nmissing packs. It happened to be up in backtrace.\nAt the moment the optimization is actually a slow down:\nno line in the header is shorter than the only key this\nfunction is ever asked for: encoding. But, in case the\nfunction ever gets asked for something longer, the old\ncondition is just wrong: it does not take into account\nthe amount of data in the line when comparing with key.\n\n commit.c |    4 +++-\n 1 files changed, 3 insertions(+), 1 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex aa7059c..d01833d 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -638,7 +638,9 @@ static char *get_header(const struct commit *commit, const char *key)\n \t\t\tnext = NULL;\n \t\t} else\n \t\t\tnext = eol + 1;\n-\t\tif (!strncmp(line, key, key_len) && line[key_len] == ' ') {\n+\t\tif (eol - line > key_len &&\n+\t\t    !strncmp(line, key, key_len) &&\n+\t\t    line[key_len] == ' ') {\n \t\t\tint len = eol - line - key_len;\n \t\t\tchar *ret = xmalloc(len);\n \t\t\tmemcpy(ret, line + key_len + 1, len - 1);\n-- \n1.5.2.rc1.21.g80e79\n"}]}