summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorAndrey Okoshkin <a.okoshkin@samsung.com>2017-10-27 09:33:25 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-10-29 01:16:36 (GMT)
commit10e0ca843dea3e8135678600f22e0baa1edf6e44 (patch)
tree4e6e9b164aaf5c3e77a1f42c58bdf54866cd3ba1 /diff.c
parent42e6fde5c28150206956ea4be490d886c4ecbd68 (diff)
downloadgit-10e0ca843dea3e8135678600f22e0baa1edf6e44.zip
git-10e0ca843dea3e8135678600f22e0baa1edf6e44.tar.gz
git-10e0ca843dea3e8135678600f22e0baa1edf6e44.tar.bz2
diff: fix lstat() error handling in diff_populate_filespec()
Add lstat() error handling not only for ENOENT case. Otherwise uninitialised 'struct stat st' variable is used later in case of lstat() non-ENOENT failure which leads to processing of rubbish values of file mode ('S_ISLNK(st.st_mode)' check) or size ('xsize_t(st.st_size)'). Signed-off-by: Andrey Okoshkin <a.okoshkin@samsung.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/diff.c b/diff.c
index 74283d9..4f72009 100644
--- a/diff.c
+++ b/diff.c
@@ -2848,14 +2848,12 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
int fd;
if (lstat(s->path, &st) < 0) {
- if (errno == ENOENT) {
- err_empty:
- err = -1;
- empty:
- s->data = (char *)"";
- s->size = 0;
- return err;
- }
+ err_empty:
+ err = -1;
+ empty:
+ s->data = (char *)"";
+ s->size = 0;
+ return err;
}
s->size = xsize_t(st.st_size);
if (!s->size)