summaryrefslogtreecommitdiff
path: root/test/sys
diff options
context:
space:
mode:
authortaylor.fish <contact@taylor.fish>2021-10-18 23:05:39 -0700
committertaylor.fish <contact@taylor.fish>2021-10-21 21:06:04 -0700
commitdc80b4cd52f7195380f9848cd780138c8a7d21f9 (patch)
treeb1c4bc150391dd35f8b8331ccfaab93b56b3d1f1 /test/sys
parent103b29ffa7f895614ff0c2f9d26774701112f4af (diff)
downloadnix-dc80b4cd52f7195380f9848cd780138c8a7d21f9.zip
Fix unsoundness in `FdSet` methods
Ensure file descriptors are nonnegative and less than `FD_SETSIZE`. (Fixes #1572.)
Diffstat (limited to 'test/sys')
-rw-r--r--test/sys/test_select.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/sys/test_select.rs b/test/sys/test_select.rs
index 37951086..db079456 100644
--- a/test/sys/test_select.rs
+++ b/test/sys/test_select.rs
@@ -52,3 +52,31 @@ pub fn test_pselect_nfds2() {
assert!(fd_set.contains(r1));
assert!(!fd_set.contains(r2));
}
+
+macro_rules! generate_fdset_bad_fd_tests {
+ ($fd:expr, $($method:ident),* $(,)?) => {
+ $(
+ #[test]
+ #[should_panic]
+ fn $method() {
+ FdSet::new().$method($fd);
+ }
+ )*
+ }
+}
+
+mod test_fdset_negative_fd {
+ use super::*;
+ generate_fdset_bad_fd_tests!(-1, insert, remove, contains);
+}
+
+mod test_fdset_too_large_fd {
+ use super::*;
+ use std::convert::TryInto;
+ generate_fdset_bad_fd_tests!(
+ FD_SETSIZE.try_into().unwrap(),
+ insert,
+ remove,
+ contains,
+ );
+}