Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-01-23 03:07:18 +0300
committerJunio C Hamano <gitster@pobox.com>2010-01-23 03:07:18 +0300
commitf986eecde1e59fc4cc2b0b761ffc0fe563dad267 (patch)
tree344856daa7c9fc2332e979eed78e1aac6faebd3d
parent4cacc621f80bbd878a320a664dff1440a9358785 (diff)
parent45d76f17182278d4c1de37b3eed60beb3b2f21ab (diff)
Merge branch 'nd/ls-files-sparse-fix'
* nd/ls-files-sparse-fix: Fix memory corruption when .gitignore does not end by \n
-rw-r--r--dir.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/dir.c b/dir.c
index 1538ad5da3..67c3af6a1a 100644
--- a/dir.c
+++ b/dir.c
@@ -242,6 +242,14 @@ int add_excludes_from_file_to_list(const char *fname,
if (!check_index ||
(buf = read_skip_worktree_file_from_index(fname, &size)) == NULL)
return -1;
+ if (size == 0) {
+ free(buf);
+ return 0;
+ }
+ if (buf[size-1] != '\n') {
+ buf = xrealloc(buf, size+1);
+ buf[size++] = '\n';
+ }
}
else {
size = xsize_t(st.st_size);
@@ -249,19 +257,21 @@ int add_excludes_from_file_to_list(const char *fname,
close(fd);
return 0;
}
- buf = xmalloc(size);
+ buf = xmalloc(size+1);
if (read_in_full(fd, buf, size) != size) {
+ free(buf);
close(fd);
return -1;
}
+ buf[size++] = '\n';
close(fd);
}
if (buf_p)
*buf_p = buf;
entry = buf;
- for (i = 0; i <= size; i++) {
- if (i == size || buf[i] == '\n') {
+ for (i = 0; i < size; i++) {
+ if (buf[i] == '\n') {
if (entry != buf + i && entry[0] != '#') {
buf[i - (i && buf[i-1] == '\r')] = 0;
add_exclude(entry, base, baselen, which);