Skip to content

Commit

Permalink
refs.c::read_ref_at(): fix bogus munmap() call.
Browse files Browse the repository at this point in the history
The code uses mmap() to read reflog data, but moves the pointer around
while reading, and uses that updated pointer in the call to munmap().

Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Junio C Hamano committed Jan 19, 2007
1 parent 2266bf2 commit cb48cb5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
struct stat st;
unsigned long date;
unsigned char logged_sha1[20];
void *log_mapped;

logfile = git_path("logs/%s", ref);
logfd = open(logfile, O_RDONLY, 0);
Expand All @@ -1033,7 +1034,8 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
fstat(logfd, &st);
if (!st.st_size)
die("Log %s is empty.", logfile);
logdata = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, logfd, 0);
log_mapped = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, logfd, 0);
logdata = log_mapped;
close(logfd);

lastrec = NULL;
Expand Down Expand Up @@ -1078,7 +1080,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
logfile, show_rfc2822_date(date, tz));
}
}
munmap((void*)logdata, st.st_size);
munmap(log_mapped, st.st_size);
return 0;
}
lastrec = rec;
Expand All @@ -1095,7 +1097,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
tz = strtoul(tz_c, NULL, 10);
if (get_sha1_hex(logdata, sha1))
die("Log %s is corrupt.", logfile);
munmap((void*)logdata, st.st_size);
munmap(log_mapped, st.st_size);
if (at_time)
fprintf(stderr, "warning: Log %s only goes back to %s.\n",
logfile, show_rfc2822_date(date, tz));
Expand Down

0 comments on commit cb48cb5

Please sign in to comment.