[PATCH] ls-files: do not trust stat info if lstat() fails

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

 



If 'err' is non-zero, lstat() has failed. Consider the entry modified
without passing the (unreliable) stat info to ce_modified() in this
case.

Noticed-by: Eric Sunshine <sunshine@xxxxxxxxxxxxxx>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 On Fri, Mar 28, 2014 at 11:04 AM, Eric Sunshine <sunshine@xxxxxxxxxxxxxx> wrote:
 > On Wed, Mar 26, 2014 at 9:48 AM, Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> wrote:
 >> +               err = lstat(ce->name, &st);
 >> +               if (show_deleted && err) {
 >> +                       show_ce_entry(tag_removed, ce);
 >> +                       shown = 1;
 >> +               }
 >> +               if (show_modified && ce_modified(ce, &st, 0)) {
 >
 > Is it possible for the lstat() to have failed for some reason when we
 > get here? If so, relying upon 'st' is unsafe, isn't it?

 The chance of random stat making ce_modified() return false is pretty
 low, but you're right. This code is a copy from the old show_files().
 I'll fix it in the git-ls series. Meanwhile a patch for maint to fix
 the original function.

 builtin/ls-files.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 47c3880..e6bd00e 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -260,7 +260,7 @@ static void show_files(struct dir_struct *dir)
 			err = lstat(ce->name, &st);
 			if (show_deleted && err)
 				show_ce_entry(tag_removed, ce);
-			if (show_modified && ce_modified(ce, &st, 0))
+			if (show_modified && (err || ce_modified(ce, &st, 0)))
 				show_ce_entry(tag_modified, ce);
 		}
 	}
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[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]