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]
#[macro_use] extern crate libfuzzer_sys;
#[macro_use]
extern crate libfuzzer_sys;
extern crate tungstenite;
use std::io;
use std::io::Cursor;
use tungstenite::WebSocket;
use tungstenite::protocol::Role;
use tungstenite::extensions::uncompressed::UncompressedExt;
use tungstenite::protocol::Role;
use tungstenite::WebSocket;
//use std::result::Result;
// 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]| {
//let vector: Vec<u8> = data.into();
let cursor = Cursor::new(data);
let mut socket: WebSocket<_, UncompressedExt> =
WebSocket::from_raw_socket(WriteMoc(cursor), Role::Client, None);
let mut socket = WebSocket::from_raw_socket(WriteMoc(cursor), Role::Client, None);
socket.read_message().ok();
});
});

@ -5,9 +5,9 @@ extern crate tungstenite;
use std::io;
use std::io::Cursor;
use tungstenite::extensions::uncompressed::UncompressedExt;
use tungstenite::protocol::Role;
use tungstenite::WebSocket;
use tungstenite::extensions::uncompressed::UncompressedExt;
//use std::result::Result;
// 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]| {
//let vector: Vec<u8> = data.into();
let cursor = Cursor::new(data);
let mut socket: WebSocket<_, UncompressedExt> =
WebSocket::from_raw_socket(WriteMoc(cursor), Role::Server, None);
let mut socket = WebSocket::from_raw_socket(WriteMoc(cursor), Role::Server, None);
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`
/// for the stream here. Any `Read + Write` streams are supported, including
/// those from `Mio` and others.
pub fn accept_with_config<Stream>(
stream: Stream,
pub fn accept_with_config<S: Read + Write>(
stream: S,
config: Option<WebSocketConfig>,
) -> Result<WebSocket<Stream>, HandshakeError<ServerHandshake<Stream, NoCallback>>>
where
Stream: Read + Write,
{
) -> Result<WebSocket<S>, HandshakeError<ServerHandshake<S, NoCallback>>> {
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
/// for header processing. The callback receives headers of the incoming
/// 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,
callback: C,
config: Option<WebSocketConfig>,
) -> Result<WebSocket<S>, HandshakeError<ServerHandshake<S, C>>>
where
S: Read + Write,
C: Callback,
{
) -> Result<WebSocket<S>, HandshakeError<ServerHandshake<S, C>>> {
ServerHandshake::start(stream, callback, config).handshake()
}

Loading…
Cancel
Save