Skip to content

Commit

Permalink
get_sha1_basic(): fix invalid memory access, found by valgrind
Browse files Browse the repository at this point in the history
When get_sha1_basic() is passed a buffer of len 0, it should not
check if buf[len-1] is a curly bracket.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Jan 27, 2009
1 parent b938f62 commit f265458
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sha1_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)

/* basic@{time or number} format to query ref-log */
reflog_len = at = 0;
if (str[len-1] == '}') {
if (len && str[len-1] == '}') {
for (at = 0; at < len - 1; at++) {
if (str[at] == '@' && str[at+1] == '{') {
reflog_len = (len-1) - (at+2);
Expand Down

0 comments on commit f265458

Please sign in to comment.