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>
This commit is contained in:
parent
42e6fde5c2
commit
10e0ca843d
14
diff.c
14
diff.c
@ -2848,14 +2848,12 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
|
|||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (lstat(s->path, &st) < 0) {
|
if (lstat(s->path, &st) < 0) {
|
||||||
if (errno == ENOENT) {
|
err_empty:
|
||||||
err_empty:
|
err = -1;
|
||||||
err = -1;
|
empty:
|
||||||
empty:
|
s->data = (char *)"";
|
||||||
s->data = (char *)"";
|
s->size = 0;
|
||||||
s->size = 0;
|
return err;
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
s->size = xsize_t(st.st_size);
|
s->size = xsize_t(st.st_size);
|
||||||
if (!s->size)
|
if (!s->size)
|
||||||
|
Loading…
Reference in New Issue
Block a user