RE: [BUG] ls-files showing deleted files (unchecked lstat return value)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On February 17, 2019 8:50, Joe Ranieri wrote:
> "git ls-files -m" can show deleted files, despite -d not having been specified.
> This is due to ls-files.c's show_files function calling lstat but not checking the
> return value before calling ie_modified with the uninitialized stat structure.

What version of git are you looking scanning? Commit 8989e1950a (2.21.0-rc1) has the following:

err = lstat(fullname.buf, &st);
if (show_deleted && err)
...

You may be correct that the following check:
 if (show_modified && ie_modified(repo->index, ce, &st, 0

may need to include !err. Is that your conclusion? Is there a test case you have to demonstrate this that I can include in the test suite?

The patch would be (subject to my bad mailer messing it up):

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 29a8762d46..fc21f47954 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -348,7 +348,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
                        err = lstat(fullname.buf, &st);
                        if (show_deleted && err)
                                show_ce(repo, dir, ce, fullname.buf, tag_removed);
-                       if (show_modified && ie_modified(repo->index, ce, &st, 0))
+                       if (show_modified && !err && ie_modified(repo->index, ce, &st, 0))
                                show_ce(repo, dir, ce, fullname.buf, tag_modified);
                }
        }

Regards,
Randall

-- Brief whoami:
 NonStop developer since approximately 211288444200000000
 UNIX developer since approximately 421664400
-- In my real life, I talk too much.






[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux