Skip to content

Commit ac07a40

Browse files
author
Colin Stolley
committed
Check packed-refs filestamp before reusing mmap.
Avoid using a stale mmap() by tracking the filestamp.
1 parent cdf05a1 commit ac07a40

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/refdb_fs.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ typedef struct refdb_fs_backend {
6767
int fsync;
6868
git_map packed_refs_map;
6969
git_mutex prlock; /* protect packed_refs_map */
70+
git_futils_filestamp packed_refs_stamp;
7071
bool sorted;
7172
} refdb_fs_backend;
7273

@@ -495,6 +496,7 @@ static void packed_map_free(refdb_fs_backend *backend)
495496
#endif
496497
backend->packed_refs_map.data = NULL;
497498
backend->packed_refs_map.len = 0;
499+
git_futils_filestamp_set(&backend->packed_refs_stamp, NULL);
498500
}
499501
}
500502

@@ -507,10 +509,13 @@ static int packed_map_check(refdb_fs_backend *backend)
507509
if ((error = git_mutex_lock(&backend->prlock)) < 0)
508510
return error;
509511

510-
if (backend->packed_refs_map.data) {
512+
if (backend->packed_refs_map.data &&
513+
!git_futils_filestamp_check(
514+
&backend->packed_refs_stamp, backend->refcache->path)) {
511515
git_mutex_unlock(&backend->prlock);
512516
return error;
513517
}
518+
packed_map_free(backend);
514519

515520
fd = git_futils_open_ro(backend->refcache->path);
516521
if (fd < 0) {
@@ -535,6 +540,8 @@ static int packed_map_check(refdb_fs_backend *backend)
535540
return 0;
536541
}
537542

543+
git_futils_filestamp_set_from_stat(&backend->packed_refs_stamp, &st);
544+
538545
#ifdef GIT_WIN32
539546
/* on windows, we copy the entire file into memory rather than using
540547
* mmap() because using mmap() on windows also locks the file and this

0 commit comments

Comments
 (0)