Fix crash in server due to overeager parsing
This commit is contained in:
parent
fc570fa0bd
commit
bf183a0598
@ -320,7 +320,7 @@ fn derive_protocol(input: proc_macro2::TokenStream) -> proc_macro2::TokenStream
|
||||
Ok(n) => {
|
||||
#debug("Received {} bytes (server)", n);
|
||||
buf.extend_from_slice(&read_buf[..n]);
|
||||
loop {
|
||||
while buf.len() >= 4 {
|
||||
let len = u32::from_le_bytes(buf[..4].try_into().expect("Failed to convert bytes to u32"));
|
||||
if buf.len() >= (4 + len as usize) {
|
||||
let serialized = std::str::from_utf8(&buf[4..(4 + len as usize)]).expect("Failed to convert bytes to string");
|
||||
|
@ -53,29 +53,42 @@ impl TestProtocolServerTrait for TrivialServer {
|
||||
async fn void(&mut self) {}
|
||||
}
|
||||
|
||||
struct Cleanup {
|
||||
address: String,
|
||||
}
|
||||
impl Drop for Cleanup {
|
||||
fn drop(&mut self) {
|
||||
std::fs::remove_file(&self.address).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn e2e() {
|
||||
init_logger();
|
||||
#[cfg(feature = "unix")]
|
||||
let address = "/tmp/eagle-test.sock";
|
||||
let address = format!("/tmp/eagle-test-{}.sock", rand::random::<u64>());
|
||||
#[cfg(feature = "unix")]
|
||||
let _cleanup = Cleanup {
|
||||
address: address.clone(),
|
||||
};
|
||||
#[cfg(feature = "tcp")]
|
||||
let address = format!("127.0.0.1:{}", 10000 + rand::random::<u64>() % 1000);
|
||||
let server_task = tokio::spawn(TestProtocolServer::bind(TrivialServer, address.clone()));
|
||||
// Wait for the server to start
|
||||
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
|
||||
let client = TestProtocolClient::connect(address).await.unwrap();
|
||||
let res = client.addition(2, 5).await.unwrap();
|
||||
// assert_eq!(client.addition(2, 5).await.unwrap(), 7);
|
||||
// assert_eq!(
|
||||
// client.some_kind_of_question("Hello, world!".to_string())
|
||||
// .await
|
||||
// .unwrap(),
|
||||
// "Hello, world!".len() as i32
|
||||
// );
|
||||
// assert_eq!(
|
||||
// client.this_responds_with_a_string(42).await.unwrap(),
|
||||
// "The number is 42"
|
||||
// );
|
||||
// client.void().await.unwrap();
|
||||
// server_task.abort();
|
||||
assert_eq!(client.addition(2, 5).await.unwrap(), 7);
|
||||
assert_eq!(
|
||||
client
|
||||
.some_kind_of_question("Hello, world!".to_string())
|
||||
.await
|
||||
.unwrap(),
|
||||
"Hello, world!".len() as i32
|
||||
);
|
||||
assert_eq!(
|
||||
client.this_responds_with_a_string(42).await.unwrap(),
|
||||
"The number is 42"
|
||||
);
|
||||
client.void().await.unwrap();
|
||||
server_task.abort();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user