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>
Andrey Okoshkin committed
Oct 27, 2017 at 12:33 UTC
10e0ca843dea3e8135678600f22e0baa1edf6e44
1 file changed
+6
-8
diff.c
+6
-8
@@ -2848,14 +2848,12 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
2848
int fd;
2849
2850
if (lstat(s->path, &st) < 0) {
2851
- if (errno == ENOENT) {
2852
- err_empty:
2853
- err = -1;
2854
- empty:
2855
- s->data = (char *)"";
2856
- s->size = 0;
2857
- return err;
2858
- }
2851
+ err_empty:
2852
+ err = -1;
2853
+ empty:
2854
+ s->data = (char *)"";
2855
+ s->size = 0;
2856
+ return err;
2857
}
2858
s->size = xsize_t(st.st_size);
2859
if (!s->size)