* [PATCH] sha1_to_hex: properly terminate the SHA1
@ 2005-12-22 17:55 Johannes Schindelin
2005-12-22 20:51 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Johannes Schindelin @ 2005-12-22 17:55 UTC (permalink / raw)
To: git, junkio
sha1_to_hex() returns a pointer to a static buffer. Some of its users
modify that buffer by appending a newline character. Other users rely
on the fact that you can call
printf("%s", sha1_to_hex(sha1));
Just to be on the safe side, terminate the SHA1 in sha1_to_hex().
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
sha1_file.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
3a743c154546e4937b4afdc7848d9943ec2f4148
diff --git a/sha1_file.c b/sha1_file.c
index 6011473..d451a94 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -81,6 +81,8 @@ char * sha1_to_hex(const unsigned char *
*buf++ = hex[val >> 4];
*buf++ = hex[val & 0xf];
}
+ *buf = '\0';
+
return buffer;
}
--
1.0.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] sha1_to_hex: properly terminate the SHA1
2005-12-22 17:55 [PATCH] sha1_to_hex: properly terminate the SHA1 Johannes Schindelin
@ 2005-12-22 20:51 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2005-12-22 20:51 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git, junkio
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> sha1_to_hex() returns a pointer to a static buffer. Some of its users
> modify that buffer by appending a newline character. Other users rely
> on the fact that you can call
>
> printf("%s", sha1_to_hex(sha1));
>
> Just to be on the safe side, terminate the SHA1 in sha1_to_hex().
Good catch, thanks. The worst one is:
diff.c:727: memcpy(one_sha1, sha1_to_hex(one->sha1), 41);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-12-22 20:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-22 17:55 [PATCH] sha1_to_hex: properly terminate the SHA1 Johannes Schindelin
2005-12-22 20:51 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox