File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 58
58
59
59
let n = {
60
60
let mut buf = ReadBuf :: uninit ( buf. bytes_mut ( ) ) ;
61
+ let before = buf. filled ( ) . as_ptr ( ) ;
62
+
61
63
ready ! ( read. poll_read( cx, & mut buf) ?) ;
64
+
65
+ // This prevents a malicious read implementation from swapping out the
66
+ // buffer being read, which would allow `filled` to be advanced without
67
+ // actually initializing the provided buffer.
68
+ //
69
+ // We avoid this by asserting that the `ReadBuf` instance wraps the same
70
+ // memory address both before and after the poll. Which will panic in
71
+ // case its swapped.
72
+ //
73
+ // See https://github.com/tokio-rs/tokio/issues/2827 for more info.
74
+ assert ! {
75
+ std:: ptr:: eq( before, buf. filled( ) . as_ptr( ) ) ,
76
+ "Read buffer must not be changed during a read poll. \
77
+ See https://github.com/tokio-rs/tokio/issues/2827 for more info."
78
+ } ;
79
+
62
80
buf. filled ( ) . len ( )
63
81
} ;
64
82
You can’t perform that action at this time.
0 commit comments