{"thread":{"id":"12414","subject":"[PATCH 1/2] index-pack: allocate NUL byte at the buffer end","startedAt":"2008-03-01T21:21:21Z","lastAt":"2008-03-02T01:06:22Z","messageCount":3,"participants":["Martin Koegler","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"70557","messageId":"12044064822655-git-send-email-mkoegler@auto.tuwien.ac.at","threadId":"12414","inReplyTo":null,"subject":"[PATCH 1/2] index-pack: allocate NUL byte at the buffer end","fromName":"Martin Koegler","fromEmail":"mkoegler@auto.tuwien.ac.at","sentAt":"2008-03-01T21:21:21Z","receivedAt":"2008-03-01T21:21:21Z","isPatch":true,"sender":{"key":"mkoegler@auto.tuwien.ac.at","avatar":null},"body":"Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>\n---\nOther parts of git add a NUL to buffers as safty measure, so why not index-pack/\nunpack-objects too?\n\n index-pack.c |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git a/index-pack.c b/index-pack.c\nindex 4bb333f..ff8e93d 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -213,7 +213,8 @@ static void bad_object(unsigned long offset, const char *format, ...)\n static void *unpack_entry_data(unsigned long offset, unsigned long size)\n {\n \tz_stream stream;\n-\tvoid *buf = xmalloc(size);\n+\tchar *buf = xmalloc(size + 1);\n+\tbuf[size] = 0;\n \n \tmemset(&stream, 0, sizeof(stream));\n \tstream.next_out = buf;\n-- \n1.5.4.2.g4b5fd.dirty\n\n"},{"id":"70558","messageId":"12044064831419-git-send-email-mkoegler@auto.tuwien.ac.at","threadId":"12414","inReplyTo":"12044064822655-git-send-email-mkoegler@auto.tuwien.ac.at","subject":"[PATCH 2/2] unpack-objects: allocate NUL byte at the buffer end","fromName":"Martin Koegler","fromEmail":"mkoegler@auto.tuwien.ac.at","sentAt":"2008-03-01T21:21:22Z","receivedAt":"2008-03-01T21:21:22Z","isPatch":true,"sender":{"key":"mkoegler@auto.tuwien.ac.at","avatar":null},"body":"Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>\n---\n builtin-unpack-objects.c |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c\nindex 9d2a854..1845abc 100644\n--- a/builtin-unpack-objects.c\n+++ b/builtin-unpack-objects.c\n@@ -86,7 +86,8 @@ static void use(int bytes)\n static void *get_data(unsigned long size)\n {\n \tz_stream stream;\n-\tvoid *buf = xmalloc(size);\n+\tchar *buf = xmalloc(size + 1);\n+\tbuf[size] = 0;\n \n \tmemset(&stream, 0, sizeof(stream));\n \n-- \n1.5.4.2.g4b5fd.dirty\n\n"},{"id":"70568","messageId":"7vablix7ch.fsf@gitster.siamese.dyndns.org","threadId":"12414","inReplyTo":"12044064822655-git-send-email-mkoegler@auto.tuwien.ac.at","subject":"Re: [PATCH 1/2] index-pack: allocate NUL byte at the buffer end","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-02T01:06:22Z","receivedAt":"2008-03-02T01:06:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Martin Koegler <mkoegler@auto.tuwien.ac.at> writes:\n\n> Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>\n> ---\n> Other parts of git add a NUL to buffers as safty measure, so why not index-pack/\n> unpack-objects too?\n\nPerhaps because nobody other than index-pack itself accesses it as if it\nis a NUL terminated buffer?\n"}]}