fsmonitor: avoid signed integer overflow / infinite loop

883e248b8a ("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 <carenas@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Carlo Marcelo Arenas Belón committed Jun 15, 2019 at 09:11 UTC 5d137fc2c7ba08455b2734c8e2ca9b9a284f3706
1 file changed +4 -4
fsmonitor.c
+4 -4
@@ -56,7 +56,7 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data,
56
57 void fill_fsmonitor_bitmap(struct index_state *istate)
58 {
59 - int i;
59 + unsigned int i;
60 istate->fsmonitor_dirty = ewah_new();
61 for (i = 0; i < istate->cache_nr; i++)
62 if (!(istate->cache[i]->ce_flags & CE_FSMONITOR_VALID))
@@ -135,7 +135,7 @@ void refresh_fsmonitor(struct index_state *istate)
135 size_t bol; /* beginning of line */
136 uint64_t last_update;
137 char *buf;
138 - int i;
138 + unsigned int i;
139
140 if (!core_fsmonitor || has_run_once)
141 return;
@@ -193,7 +193,7 @@ void refresh_fsmonitor(struct index_state *istate)
193
194 void add_fsmonitor(struct index_state *istate)
195 {
196 - int i;
196 + unsigned int i;
197
198 if (!istate->fsmonitor_last_update) {
199 trace_printf_key(&trace_fsmonitor, "add fsmonitor");
@@ -226,7 +226,7 @@ void remove_fsmonitor(struct index_state *istate)
226
227 void tweak_fsmonitor(struct index_state *istate)
228 {
229 - int i;
229 + unsigned int i;
230 int fsmonitor_enabled = git_config_get_fsmonitor();
231
232 if (istate->fsmonitor_dirty) {