Skip to content
This repository has been archived by the owner on Nov 28, 2020. It is now read-only.

Commit

Permalink
Fixed UB in setsockopt_option_scalar
Browse files Browse the repository at this point in the history
* Also whitelisted some clippy dead_code warnings.
  • Loading branch information
jean-airoldie committed Dec 30, 2019
1 parent 3868edd commit 71d9f9f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
18 changes: 13 additions & 5 deletions libzmq/src/core/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::{
const MAX_OPTION_SIZE: size_t = 255;

#[derive(Copy, Clone, Debug)]
#[allow(dead_code)]
pub(crate) enum SocketOption {
Backlog = sys::ZMQ_BACKLOG as isize,
ConnectTimeout = sys::ZMQ_CONNECT_TIMEOUT as isize,
Expand Down Expand Up @@ -262,11 +263,16 @@ where
{
let size = mem::size_of::<T>() as size_t;

let value_ptr = match maybe {
Some(value) => &value as *const T as *const c_void,
None => &none_value as *const T as *const c_void,
};
setsockopt(mut_sock_ptr, option, value_ptr, size)
match maybe {
Some(value) => {
let value_ptr = &value as *const T as *const c_void;
setsockopt(mut_sock_ptr, option, value_ptr, size)
}
None => {
let value_ptr = &none_value as *const T as *const c_void;
setsockopt(mut_sock_ptr, option, value_ptr, size)
}
}
}

pub(crate) fn setsockopt_bytes(
Expand Down Expand Up @@ -311,6 +317,8 @@ pub(crate) fn setsockopt_option_duration(
check_duration(duration)?;
}

dbg!(option, maybe);

setsockopt_option_scalar(
mut_sock_ptr,
option,
Expand Down
1 change: 1 addition & 0 deletions libzmq/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ lazy_static! {
}

#[derive(Copy, Clone, Debug)]
#[allow(dead_code)]
enum CtxOption {
IOThreads,
MaxSockets,
Expand Down
1 change: 1 addition & 0 deletions libzmq/src/old.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fn recv(mut_sock_ptr: *mut c_void, msg: &mut Msg) -> Result<(), Error> {
}
}

#[allow(dead_code)]
pub(crate) enum OldSocketType {
Router,
Dealer,
Expand Down
10 changes: 10 additions & 0 deletions libzmq/src/socket/gather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ mod test {
use super::*;
use crate::*;

use std::time::Duration;

#[test]
fn test_ser_de() {
let config = GatherConfig::new();
Expand All @@ -323,6 +325,14 @@ mod test {
assert_eq!(config, de);
}

#[test]
fn test_issue_125() {
let gather = Gather::new().unwrap();
gather
.set_recv_timeout(Some(Duration::from_secs(3)))
.unwrap();
}

#[test]
fn test_gather() {
let addr_a = InprocAddr::new_unique();
Expand Down

0 comments on commit 71d9f9f

Please sign in to comment.