-
Notifications
You must be signed in to change notification settings - Fork 5
/
0110-libp2p-deflate.rs
86 lines (71 loc) · 2 KB
/
0110-libp2p-deflate.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*!
```rudra-poc
[target]
crate = "libp2p-deflate"
version = "0.27.0"
indexed_version = "0.20.0"
[[target.peer]]
crate = "libp2p-core"
version = "0.27.0"
[[target.peer]]
crate = "futures"
version = "0.3.12"
features = ["executor"]
[report]
issue_url = "https://github.com/libp2p/rust-libp2p/issues/1932"
issue_date = 2020-01-24
rustsec_url = "https://github.com/RustSec/advisory-db/pull/700"
rustsec_id = "RUSTSEC-2020-0123"
[[bugs]]
analyzer = "UnsafeDataflow"
bug_class = "UninitExposure"
rudra_report_locations = ["src/lib.rs:128:5: 174:6"]
```
!*/
#![forbid(unsafe_code)]
use libp2p_core::upgrade::{InboundUpgrade, ProtocolName};
use libp2p_deflate::DeflateConfig;
use futures::executor;
use futures::io::{AsyncRead, AsyncReadExt, AsyncWrite, Error};
use futures::task::{Context, Poll};
use std::pin::Pin;
struct BrokenReader();
impl AsyncRead for BrokenReader {
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8],
) -> Poll<Result<usize, Error>> {
// Dump out uninitialized memory
println!("{:?}", buf);
assert!(buf[0] == 0);
return Poll::Ready(Ok(buf.len()));
}
}
impl AsyncWrite for BrokenReader {
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8],
) -> Poll<Result<usize, Error>> {
return Poll::Ready(Ok(buf.len()));
}
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Error>> {
return Poll::Ready(Ok(()));
}
fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Error>> {
return Poll::Ready(Ok(()));
}
}
fn main() {
executor::block_on(async {
let broken_reader = BrokenReader();
let deflate_config = DeflateConfig::default();
let mut deflate_output = deflate_config
.upgrade_inbound(broken_reader, "/test/1".as_bytes())
.await
.unwrap();
let mut buf = [1u8; 256];
deflate_output.read_exact(&mut buf).await.unwrap();
});
}