summaryrefslogtreecommitdiff
path: root/test/sys/test_socket.rs
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2019-01-15 09:23:33 -0700
committerAlan Somers <asomers@gmail.com>2019-02-14 10:15:49 -0700
commit368b9fe9436734f7fccffa2fdf3e723ee20fb836 (patch)
tree7477402cb795d097f03c88509679d5b8b926f59a /test/sys/test_socket.rs
parented1c90d6bc9871d9881e8fcb05370752b6a5d25b (diff)
downloadnix-368b9fe9436734f7fccffa2fdf3e723ee20fb836.zip
Fix error handling of RecvMsg
There were two problems: 1) It would always return Ok, even on error 2) It could panic if there was an error, because sockaddr_storage_to_addr would be called on uninitialized memory.
Diffstat (limited to 'test/sys/test_socket.rs')
-rw-r--r--test/sys/test_socket.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs
index 2cc3475f..cc8c6f89 100644
--- a/test/sys/test_socket.rs
+++ b/test/sys/test_socket.rs
@@ -117,6 +117,21 @@ pub fn test_socketpair() {
assert_eq!(&buf[..], b"hello");
}
+// Test error handling of our recvmsg wrapper
+#[test]
+pub fn test_recvmsg_ebadf() {
+ use nix::Error;
+ use nix::errno::Errno;
+ use nix::sys::socket::{MsgFlags, recvmsg};
+ use nix::sys::uio::IoVec;
+
+ let mut buf = [0u8; 5];
+ let iov = [IoVec::from_mut_slice(&mut buf[..])];
+ let fd = -1; // Bad file descriptor
+ let r = recvmsg::<()>(fd, &iov, None, MsgFlags::empty());
+ assert_eq!(r.err().unwrap(), Error::Sys(Errno::EBADF));
+}
+
#[test]
pub fn test_scm_rights() {
use nix::sys::uio::IoVec;