diff options
author | Ben S <ogham@bsago.me> | 2015-02-23 13:37:59 +0000 |
---|---|---|
committer | Ben S <ogham@bsago.me> | 2015-02-23 13:37:59 +0000 |
commit | 38a785426bda54db3adeeb7edf991fd8c4d78e30 (patch) | |
tree | 164303399d09d8b731f6787cd416502aeb5b5549 /src/file.rs | |
parent | 1da1142a7ef049017a35b2af76ece3ce9a43fc36 (diff) |
Fix overflowing UIDs and GIDs
Fixes #26.
Diffstat (limited to 'src/file.rs')
-rw-r--r-- | src/file.rs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/file.rs b/src/file.rs index 6d89fef..9ba686e 100644 --- a/src/file.rs +++ b/src/file.rs @@ -263,7 +263,7 @@ impl<'a> File<'a> { let user_name = match users_cache.get_user_by_uid(uid) { Some(user) => user.name, - None => uid.to_string(), + None => self.stat.unstable.uid.to_string(), }; let style = if users_cache.get_current_uid() == uid { Yellow.bold() } else { Plain }; @@ -287,7 +287,7 @@ impl<'a> File<'a> { } group.name }, - None => gid.to_string(), + None => self.stat.unstable.gid.to_string(), }; Cell::paint(style, &*group_name) @@ -601,6 +601,19 @@ pub mod test { let cell = Cell::paint(Plain, "1000"); assert_eq!(cell, file.display(&Column::User, &mut users, &dummy_locale())) } + + #[test] + fn overflow() { + let mut stat = dummy_stat(); + stat.unstable.uid = 2_147_483_648; + + let file = new_file(stat, "/hi"); + + let mut users = MockUsers::with_current_uid(3); + + let cell = Cell::paint(Plain, "2147483648"); + assert_eq!(cell, file.display(&Column::User, &mut users, &dummy_locale())) + } } mod groups { @@ -662,5 +675,18 @@ pub mod test { let cell = Cell::paint(Yellow.bold(), "folk"); assert_eq!(cell, file.display(&Column::Group, &mut users, &dummy_locale())) } + + #[test] + fn overflow() { + let mut stat = dummy_stat(); + stat.unstable.gid = 2_147_483_648; + + let file = new_file(stat, "/hi"); + + let mut users = MockUsers::with_current_uid(3); + + let cell = Cell::paint(Plain, "2147483648"); + assert_eq!(cell, file.display(&Column::Group, &mut users, &dummy_locale())) + } } } |