pull/144/head
SirCipher 4 years ago
parent 2dab65174a
commit a7f07028a7
  1. 12
      fuzz/fuzz_targets/read_message_client.rs
  2. 5
      fuzz/fuzz_targets/read_message_server.rs
  3. 17
      src/server.rs

@ -1,12 +1,13 @@
#![no_main] #![no_main]
#[macro_use] extern crate libfuzzer_sys; #[macro_use]
extern crate libfuzzer_sys;
extern crate tungstenite; extern crate tungstenite;
use std::io; use std::io;
use std::io::Cursor; use std::io::Cursor;
use tungstenite::WebSocket;
use tungstenite::protocol::Role;
use tungstenite::extensions::uncompressed::UncompressedExt; use tungstenite::extensions::uncompressed::UncompressedExt;
use tungstenite::protocol::Role;
use tungstenite::WebSocket;
//use std::result::Result; //use std::result::Result;
// FIXME: copypasted from tungstenite's protocol/mod.rs // FIXME: copypasted from tungstenite's protocol/mod.rs
@ -33,7 +34,6 @@ impl<Stream: io::Read> io::Read for WriteMoc<Stream> {
fuzz_target!(|data: &[u8]| { fuzz_target!(|data: &[u8]| {
//let vector: Vec<u8> = data.into(); //let vector: Vec<u8> = data.into();
let cursor = Cursor::new(data); let cursor = Cursor::new(data);
let mut socket: WebSocket<_, UncompressedExt> = let mut socket = WebSocket::from_raw_socket(WriteMoc(cursor), Role::Client, None);
WebSocket::from_raw_socket(WriteMoc(cursor), Role::Client, None);
socket.read_message().ok(); socket.read_message().ok();
}); });

@ -5,9 +5,9 @@ extern crate tungstenite;
use std::io; use std::io;
use std::io::Cursor; use std::io::Cursor;
use tungstenite::extensions::uncompressed::UncompressedExt;
use tungstenite::protocol::Role; use tungstenite::protocol::Role;
use tungstenite::WebSocket; use tungstenite::WebSocket;
use tungstenite::extensions::uncompressed::UncompressedExt;
//use std::result::Result; //use std::result::Result;
// FIXME: copypasted from tungstenite's protocol/mod.rs // FIXME: copypasted from tungstenite's protocol/mod.rs
@ -34,7 +34,6 @@ impl<Stream: io::Read> io::Read for WriteMoc<Stream> {
fuzz_target!(|data: &[u8]| { fuzz_target!(|data: &[u8]| {
//let vector: Vec<u8> = data.into(); //let vector: Vec<u8> = data.into();
let cursor = Cursor::new(data); let cursor = Cursor::new(data);
let mut socket: WebSocket<_, UncompressedExt> = let mut socket = WebSocket::from_raw_socket(WriteMoc(cursor), Role::Server, None);
WebSocket::from_raw_socket(WriteMoc(cursor), Role::Server, None);
socket.read_message().ok(); socket.read_message().ok();
}); });

@ -20,13 +20,10 @@ use std::io::{Read, Write};
/// If you want TLS support, use `native_tls::TlsStream` or `openssl::ssl::SslStream` /// If you want TLS support, use `native_tls::TlsStream` or `openssl::ssl::SslStream`
/// for the stream here. Any `Read + Write` streams are supported, including /// for the stream here. Any `Read + Write` streams are supported, including
/// those from `Mio` and others. /// those from `Mio` and others.
pub fn accept_with_config<Stream>( pub fn accept_with_config<S: Read + Write>(
stream: Stream, stream: S,
config: Option<WebSocketConfig>, config: Option<WebSocketConfig>,
) -> Result<WebSocket<Stream>, HandshakeError<ServerHandshake<Stream, NoCallback>>> ) -> Result<WebSocket<S>, HandshakeError<ServerHandshake<S, NoCallback>>> {
where
Stream: Read + Write,
{
accept_hdr_with_config(stream, NoCallback, config) accept_hdr_with_config(stream, NoCallback, config)
} }
@ -50,15 +47,11 @@ pub fn accept<S: Read + Write>(
/// This function does the same as `accept()` but accepts an extra callback /// This function does the same as `accept()` but accepts an extra callback
/// for header processing. The callback receives headers of the incoming /// for header processing. The callback receives headers of the incoming
/// requests and is able to add extra headers to the reply. /// requests and is able to add extra headers to the reply.
pub fn accept_hdr_with_config<S, C>( pub fn accept_hdr_with_config<S: Read + Write, C: Callback>(
stream: S, stream: S,
callback: C, callback: C,
config: Option<WebSocketConfig>, config: Option<WebSocketConfig>,
) -> Result<WebSocket<S>, HandshakeError<ServerHandshake<S, C>>> ) -> Result<WebSocket<S>, HandshakeError<ServerHandshake<S, C>>> {
where
S: Read + Write,
C: Callback,
{
ServerHandshake::start(stream, callback, config).handshake() ServerHandshake::start(stream, callback, config).handshake()
} }

Loading…
Cancel
Save