Skip to content

Commit f2e86ed

Browse files
committed
add hard cap to OTA chunk size
1 parent 739a24a commit f2e86ed

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/server/client_handle.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ use std::{io::Read, net::SocketAddr, sync::Arc};
1010
use tokio::{net::TcpStream, time::timeout};
1111
use tracing::{debug, error, warn};
1212

13+
/// Maximum OTA chunk size a client can request.
14+
const MAX_OTA_CHUNK_SIZE: u32 = 4 * 1024; // 4 MiB
15+
1316
#[allow(clippy::needless_pass_by_value, clippy::cognitive_complexity)]
1417
pub async fn handle_client(
1518
client: TcpStream,
@@ -153,6 +156,10 @@ async fn handle_request(
153156
}
154157
}
155158
Request::NextUpdateChunk(chunk_size) => {
159+
if chunk_size > MAX_OTA_CHUNK_SIZE {
160+
return Ok(Response::InvalidRequest);
161+
}
162+
156163
let Some(reader) = client.update_chunk() else {
157164
error!(
158165
"{}: Requested update when there is none available",

0 commit comments

Comments
 (0)