]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsmonitor: avoid signed integer overflow / infinite loop
authorCarlo Marcelo Arenas Belón <carenas@gmail.com>
Sat, 15 Jun 2019 16:11:35 +0000 (09:11 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Jun 2019 01:14:29 +0000 (18:14 -0700)
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>
fsmonitor.c

index 665bd2d4254b12edf38e94cb0e8b2200ae3bf34a..df55d9dc2293615361b12b1e41219a479c1f073e 100644 (file)
@@ -56,7 +56,7 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data,
 
 void fill_fsmonitor_bitmap(struct index_state *istate)
 {
-       int i;
+       unsigned int i;
        istate->fsmonitor_dirty = ewah_new();
        for (i = 0; i < istate->cache_nr; i++)
                if (!(istate->cache[i]->ce_flags & CE_FSMONITOR_VALID))
@@ -135,7 +135,7 @@ void refresh_fsmonitor(struct index_state *istate)
        size_t bol; /* beginning of line */
        uint64_t last_update;
        char *buf;
-       int i;
+       unsigned int i;
 
        if (!core_fsmonitor || has_run_once)
                return;
@@ -193,7 +193,7 @@ void refresh_fsmonitor(struct index_state *istate)
 
 void add_fsmonitor(struct index_state *istate)
 {
-       int i;
+       unsigned int i;
 
        if (!istate->fsmonitor_last_update) {
                trace_printf_key(&trace_fsmonitor, "add fsmonitor");
@@ -226,7 +226,7 @@ void remove_fsmonitor(struct index_state *istate)
 
 void tweak_fsmonitor(struct index_state *istate)
 {
-       int i;
+       unsigned int i;
        int fsmonitor_enabled = git_config_get_fsmonitor();
 
        if (istate->fsmonitor_dirty) {