File tree Expand file tree Collapse file tree 4 files changed +18
-15
lines changed
Expand file tree Collapse file tree 4 files changed +18
-15
lines changed Original file line number Diff line number Diff line change @@ -106,9 +106,7 @@ impl Log {
106106 for forwarded_ip in forwarded_ips {
107107 match forwarded_ip. parse :: < Addr > ( ) {
108108 Ok ( addr) => ips. push ( addr. addr ) ,
109- Err ( ( ) ) => {
110- log:: error!( "cannot parse ip address {}, skipping" , forwarded_ip) ;
111- }
109+ Err ( ( ) ) => ( ) ,
112110 }
113111 }
114112 }
@@ -123,9 +121,7 @@ impl Log {
123121
124122 match ip. parse :: < Addr > ( ) {
125123 Ok ( ip) => ips. push ( ip. addr ) ,
126- Err ( ( ) ) => {
127- log:: error!( "cannot parse ip address {}, skipping" , ip) ;
128- }
124+ Err ( ( ) ) => ( ) ,
129125 }
130126 }
131127 }
Original file line number Diff line number Diff line change @@ -27,9 +27,11 @@ impl FromStr for Addr {
2727 type Err = ( ) ;
2828
2929 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
30- if let Ok ( addr) = s. parse :: < IpAddr > ( ) {
30+ let trimmed = s. trim_matches ( |c| c == '\0' || c == '\n' || c == '\r' || c == '\t' || c == ' ' ) ;
31+
32+ if let Ok ( addr) = trimmed. parse :: < IpAddr > ( ) {
3133 Ok ( Self { addr, port : None } )
32- } else if let Ok ( sock) = s . parse :: < SocketAddr > ( ) {
34+ } else if let Ok ( sock) = trimmed . parse :: < SocketAddr > ( ) {
3335 Ok ( Self {
3436 addr : sock. ip ( ) ,
3537 port : Some ( sock. port ( ) ) ,
@@ -60,6 +62,15 @@ mod tests {
6062 assert_eq ! ( addr. addr. to_string( ) , "127.0.0.1" ) ;
6163 }
6264
65+ #[ test]
66+ fn test_ipv4_with_null ( ) {
67+ let addr = "127.0.0.1\0 " . parse :: < Addr > ( ) . unwrap ( ) ;
68+
69+ assert ! ( addr. addr. is_ipv4( ) ) ;
70+ assert ! ( addr. port. is_none( ) ) ;
71+ assert_eq ! ( addr. addr. to_string( ) , "127.0.0.1" ) ;
72+ }
73+
6374 #[ test]
6475 fn test_ipv4_with_port ( ) {
6576 let addr = "127.0.0.1:8080" . parse :: < Addr > ( ) . unwrap ( ) ;
Original file line number Diff line number Diff line change @@ -7,9 +7,9 @@ mod trusted_proxies;
77#[ cfg( not( target_arch = "wasm32" ) ) ]
88pub mod ffi;
99
10+ pub use addr:: Addr ;
1011pub use header:: Header ;
1112pub use query:: sanitize_url;
1213pub use query:: PathAndQueryWithSkipped ;
1314pub use request:: Request ;
1415pub use trusted_proxies:: TrustedProxies ;
15- pub use addr:: Addr ;
Original file line number Diff line number Diff line change @@ -277,9 +277,7 @@ impl Request {
277277
278278 match ip. parse :: < Addr > ( ) {
279279 Ok ( ip) => ips. push ( ip. addr ) ,
280- Err ( ( ) ) => {
281- log:: error!( "-cannot parse ip address {}, skipping" , ip) ;
282- }
280+ Err ( ( ) ) => ( ) ,
283281 }
284282 }
285283 }
@@ -289,9 +287,7 @@ impl Request {
289287
290288 match ip. parse :: < Addr > ( ) {
291289 Ok ( ip) => ips. push ( ip. addr ) ,
292- Err ( ( ) ) => {
293- log:: error!( "cannot parse ip address {}, skipping" , ip) ;
294- }
290+ Err ( ( ) ) => ( ) ,
295291 }
296292 }
297293
You can’t perform that action at this time.
0 commit comments