]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff: fix lstat() error handling in diff_populate_filespec()
authorAndrey Okoshkin <a.okoshkin@samsung.com>
Fri, 27 Oct 2017 09:33:25 +0000 (12:33 +0300)
committerJunio C Hamano <gitster@pobox.com>
Sun, 29 Oct 2017 01:16:36 +0000 (10:16 +0900)
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>
diff.c

diff --git a/diff.c b/diff.c
index 74283d9001fbc48d11ba5c449ea7c16692791c88..4f72009e87dc41c7ea52e74f6dfcbce4bcea05cd 100644 (file)
--- 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)