Skip to content

Commit 1aa3dff

Browse files
committed
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
2 parents d3e54ed + 398e659 commit 1aa3dff

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3115,7 +3115,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
31153115
}
31163116

31173117
while (fgets(buf, sizeof(buf), config_file)) {
3118-
int i;
3118+
unsigned i;
31193119
int length;
31203120
int is_section = 0;
31213121
char *output = buf;

revision.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,6 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
669669
struct pathspec_item *pi;
670670
char *path_alloc = NULL;
671671
const char *path, *p;
672-
int last_index;
673672
size_t len;
674673
int path_component_nr = 1;
675674

@@ -692,19 +691,18 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
692691
return;
693692

694693
pi = &revs->pruning.pathspec.items[0];
695-
last_index = pi->len - 1;
696694

697695
/* remove single trailing slash from path, if needed */
698-
if (pi->match[last_index] == '/') {
699-
path_alloc = xstrdup(pi->match);
700-
path_alloc[last_index] = '\0';
696+
if (pi->len > 0 && pi->match[pi->len - 1] == '/') {
697+
path_alloc = xmemdupz(pi->match, pi->len - 1);
701698
path = path_alloc;
702699
} else
703700
path = pi->match;
704701

705702
len = strlen(path);
706703
if (!len) {
707704
revs->bloom_filter_settings = NULL;
705+
free(path_alloc);
708706
return;
709707
}
710708

0 commit comments

Comments
 (0)