{"thread":{"id":"2908","subject":"[PATCH] sha1_to_hex: properly terminate the SHA1","startedAt":"2005-12-22T17:55:59Z","lastAt":"2005-12-22T20:51:59Z","messageCount":2,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"13948","messageId":"Pine.LNX.4.63.0512221854550.20025@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2908","inReplyTo":null,"subject":"[PATCH] sha1_to_hex: properly terminate the SHA1","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-22T17:55:59Z","receivedAt":"2005-12-22T17:55:59Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nsha1_to_hex() returns a pointer to a static buffer. Some of its users\nmodify that buffer by appending a newline character. Other users rely\non the fact that you can call\n\n\tprintf(\"%s\", sha1_to_hex(sha1));\n\nJust to be on the safe side, terminate the SHA1 in sha1_to_hex().\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n sha1_file.c |    2 ++\n 1 files changed, 2 insertions(+), 0 deletions(-)\n\n3a743c154546e4937b4afdc7848d9943ec2f4148\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 6011473..d451a94 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -81,6 +81,8 @@ char * sha1_to_hex(const unsigned char *\n \t\t*buf++ = hex[val >> 4];\n \t\t*buf++ = hex[val & 0xf];\n \t}\n+\t*buf = '\\0';\n+\n \treturn buffer;\n }\n \n-- \n1.0.0\n"},{"id":"13958","messageId":"7voe38j1n4.fsf@assigned-by-dhcp.cox.net","threadId":"2908","inReplyTo":"Pine.LNX.4.63.0512221854550.20025@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] sha1_to_hex: properly terminate the SHA1","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-22T20:51:59Z","receivedAt":"2005-12-22T20:51:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> sha1_to_hex() returns a pointer to a static buffer. Some of its users\n> modify that buffer by appending a newline character. Other users rely\n> on the fact that you can call\n>\n> \tprintf(\"%s\", sha1_to_hex(sha1));\n>\n> Just to be on the safe side, terminate the SHA1 in sha1_to_hex().\n\nGood catch, thanks.  The worst one is:\n\ndiff.c:727:\t\tmemcpy(one_sha1, sha1_to_hex(one->sha1), 41);\n"}]}