@@ -43,6 +43,7 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
43
43
let reader;
44
44
let mut name;
45
45
let mut tries = 0 ;
46
+ let mut reject_remote_clients_flag = c:: PIPE_REJECT_REMOTE_CLIENTS ;
46
47
loop {
47
48
tries += 1 ;
48
49
let key: u64 = rand:: thread_rng ( ) . gen ( ) ;
@@ -56,12 +57,12 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
56
57
57
58
let handle = c:: CreateNamedPipeW ( wide_name. as_ptr ( ) ,
58
59
c:: PIPE_ACCESS_INBOUND |
59
- c:: FILE_FLAG_FIRST_PIPE_INSTANCE |
60
- c:: FILE_FLAG_OVERLAPPED ,
60
+ c:: FILE_FLAG_FIRST_PIPE_INSTANCE |
61
+ c:: FILE_FLAG_OVERLAPPED ,
61
62
c:: PIPE_TYPE_BYTE |
62
- c:: PIPE_READMODE_BYTE |
63
- c:: PIPE_WAIT |
64
- c :: PIPE_REJECT_REMOTE_CLIENTS ,
63
+ c:: PIPE_READMODE_BYTE |
64
+ c:: PIPE_WAIT |
65
+ reject_remote_clients_flag ,
65
66
1 ,
66
67
4096 ,
67
68
4096 ,
@@ -76,11 +77,27 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
76
77
//
77
78
// Don't try again too much though as this could also perhaps be a
78
79
// legit error.
80
+ // If ERROR_INVALID_PARAMETER is returned, this probably means we're
81
+ // running on pre-Vista version where PIPE_REJECT_REMOTE_CLIENTS is
82
+ // not supported, so we continue retrying without it. This implies
83
+ // reduced security on Windows versions older than Vista by allowing
84
+ // connections to this pipe from remote machines.
85
+ // Proper fix would increase the number of FFI imports and introduce
86
+ // significant amount of Windows XP specific code with no clean
87
+ // testing strategy
88
+ // for more info see https://github.com/rust-lang/rust/pull/37677
79
89
if handle == c:: INVALID_HANDLE_VALUE {
80
90
let err = io:: Error :: last_os_error ( ) ;
81
- if tries < 10 &&
82
- err. raw_os_error ( ) == Some ( c:: ERROR_ACCESS_DENIED as i32 ) {
83
- continue
91
+ let raw_os_err = err. raw_os_error ( ) ;
92
+ if tries < 10 {
93
+ if raw_os_err == Some ( c:: ERROR_ACCESS_DENIED as i32 ) {
94
+ continue
95
+ } else if reject_remote_clients_flag != 0 &&
96
+ raw_os_err == Some ( c:: ERROR_INVALID_PARAMETER as i32 ) {
97
+ reject_remote_clients_flag = 0 ;
98
+ tries -= 1 ;
99
+ continue
100
+ }
84
101
}
85
102
return Err ( err)
86
103
}
0 commit comments