Skip to content

Commit 5d137fc

Browse files
carenasgitster
authored andcommitted
fsmonitor: avoid signed integer overflow / infinite loop
883e248 ("fsmonitor: teach git to optionally utilize a file system monitor to speed up detecting new or changed files.", 2017-09-22) uses an int in a loop that would wrap if index_state->cache_nr (unsigned) is bigger than INT_MAX Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aeb582a commit 5d137fc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

fsmonitor.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data,
5656

5757
void fill_fsmonitor_bitmap(struct index_state *istate)
5858
{
59-
int i;
59+
unsigned int i;
6060
istate->fsmonitor_dirty = ewah_new();
6161
for (i = 0; i < istate->cache_nr; i++)
6262
if (!(istate->cache[i]->ce_flags & CE_FSMONITOR_VALID))
@@ -135,7 +135,7 @@ void refresh_fsmonitor(struct index_state *istate)
135135
size_t bol; /* beginning of line */
136136
uint64_t last_update;
137137
char *buf;
138-
int i;
138+
unsigned int i;
139139

140140
if (!core_fsmonitor || has_run_once)
141141
return;
@@ -193,7 +193,7 @@ void refresh_fsmonitor(struct index_state *istate)
193193

194194
void add_fsmonitor(struct index_state *istate)
195195
{
196-
int i;
196+
unsigned int i;
197197

198198
if (!istate->fsmonitor_last_update) {
199199
trace_printf_key(&trace_fsmonitor, "add fsmonitor");
@@ -226,7 +226,7 @@ void remove_fsmonitor(struct index_state *istate)
226226

227227
void tweak_fsmonitor(struct index_state *istate)
228228
{
229-
int i;
229+
unsigned int i;
230230
int fsmonitor_enabled = git_config_get_fsmonitor();
231231

232232
if (istate->fsmonitor_dirty) {

0 commit comments

Comments
 (0)