66#[ cfg( feature = "proxy" ) ]
77use socks:: Socks5Stream ;
88use std:: io:: { BufRead , BufReader , Read , Write } ;
9+ #[ cfg( not( fuzzing) ) ]
910use std:: net:: TcpStream ;
1011use std:: net:: { SocketAddr , ToSocketAddrs } ;
1112use std:: sync:: { Arc , Mutex } ;
@@ -19,6 +20,43 @@ use serde_json;
1920use crate :: client:: Transport ;
2021use crate :: { Request , Response } ;
2122
23+ #[ cfg( fuzzing) ]
24+ /// Global mutex used by the fuzzing harness to inject data into the read
25+ /// end of the TCP stream.
26+ pub static FUZZ_TCP_SOCK : Mutex < Option < io:: Cursor < Vec < u8 > > > > = Mutex :: new ( None ) ;
27+
28+ #[ cfg( fuzzing) ]
29+ #[ derive( Clone , Debug ) ]
30+ struct TcpStream ;
31+
32+ #[ cfg( fuzzing) ]
33+ mod impls {
34+ use super :: * ;
35+ impl Read for TcpStream {
36+ fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
37+ match * FUZZ_TCP_SOCK . lock ( ) . unwrap ( ) {
38+ Some ( ref mut cursor) => io:: Read :: read ( cursor, buf) ,
39+ None => Ok ( 0 ) ,
40+ }
41+ }
42+ }
43+ impl Write for TcpStream {
44+ fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
45+ io:: sink ( ) . write ( buf)
46+ }
47+ fn flush ( & mut self ) -> io:: Result < ( ) > {
48+ Ok ( ( ) )
49+ }
50+ }
51+
52+ impl TcpStream {
53+ pub fn connect_timeout ( _: & SocketAddr , _: Duration ) -> io:: Result < Self > { Ok ( TcpStream ) }
54+ pub fn set_read_timeout ( & self , _: Option < Duration > ) -> io:: Result < ( ) > { Ok ( ( ) ) }
55+ pub fn set_write_timeout ( & self , _: Option < Duration > ) -> io:: Result < ( ) > { Ok ( ( ) ) }
56+ }
57+ }
58+
59+
2260/// The default TCP port to use for connections.
2361/// Set to 8332, the default RPC port for bitcoind.
2462pub const DEFAULT_PORT : u16 = 8332 ;
0 commit comments