diff options
author | Alan Somers <asomers@gmail.com> | 2019-01-15 09:23:33 -0700 |
---|---|---|
committer | Alan Somers <asomers@gmail.com> | 2019-02-14 10:15:49 -0700 |
commit | 368b9fe9436734f7fccffa2fdf3e723ee20fb836 (patch) | |
tree | 7477402cb795d097f03c88509679d5b8b926f59a /test/sys/test_socket.rs | |
parent | ed1c90d6bc9871d9881e8fcb05370752b6a5d25b (diff) | |
download | nix-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.rs | 15 |
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; |