diff options
author | Junio C Hamano <gitster@pobox.com> | 2020-08-10 20:24:02 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-08-10 20:24:02 +0300 |
commit | 1aa3dff4ba492483a4cce0a3aa315cfc05b0bdd3 (patch) | |
tree | 8090ab51ec810d57ebe4d9baf1b800ea1cf25c59 /revision.c | |
parent | d3e54edb93cb24de10bd040d927f86179b463da5 (diff) | |
parent | 398e659e1ec60501d67a0f3cb1a1052c6e50038c (diff) |
Merge branch 'jk/compiler-fixes-and-workarounds'
Small fixes and workarounds.
* jk/compiler-fixes-and-workarounds:
revision: avoid leak when preparing bloom filter for "/"
revision: avoid out-of-bounds read/write on empty pathspec
config: work around gcc-10 -Wstringop-overflow warning
Diffstat (limited to 'revision.c')
-rw-r--r-- | revision.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/revision.c b/revision.c index d1d14821d3..96a68077ed 100644 --- a/revision.c +++ b/revision.c @@ -669,7 +669,6 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs) struct pathspec_item *pi; char *path_alloc = NULL; const char *path, *p; - int last_index; size_t len; int path_component_nr = 1; @@ -692,12 +691,10 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs) return; pi = &revs->pruning.pathspec.items[0]; - last_index = pi->len - 1; /* remove single trailing slash from path, if needed */ - if (pi->match[last_index] == '/') { - path_alloc = xstrdup(pi->match); - path_alloc[last_index] = '\0'; + if (pi->len > 0 && pi->match[pi->len - 1] == '/') { + path_alloc = xmemdupz(pi->match, pi->len - 1); path = path_alloc; } else path = pi->match; @@ -705,6 +702,7 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs) len = strlen(path); if (!len) { revs->bloom_filter_settings = NULL; + free(path_alloc); return; } |