Skip to content

Commit 10e0ca8

Browse files
okodrongitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 42e6fde commit 10e0ca8

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

diff.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,14 +2848,12 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
28482848
int fd;
28492849

28502850
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;
28592857
}
28602858
s->size = xsize_t(st.st_size);
28612859
if (!s->size)

0 commit comments

Comments
 (0)