Skip to content

Commit f265458

Browse files
dschogitster
authored andcommitted
get_sha1_basic(): fix invalid memory access, found by valgrind
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b938f62 commit f265458

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

sha1_name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
309309

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

0 commit comments

Comments
 (0)