Skip to content

Commit c170f48

Browse files
authored
fine-tune MAX_MSG_ABSOLUTE (#170)
1 parent e5bda10 commit c170f48

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/dns_parser.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ pub(crate) const CLASS_IN: u16 = 1;
3232
pub(crate) const CLASS_MASK: u16 = 0x7FFF;
3333
pub(crate) const CLASS_UNIQUE: u16 = 0x8000;
3434

35-
pub(crate) const MAX_MSG_ABSOLUTE: usize = 8966;
35+
/// Max size of UDP datagram payload: 9000 bytes - IP header 20 bytes - UDP header 8 bytes.
36+
/// Reference: RFC6762: https://datatracker.ietf.org/doc/html/rfc6762#section-17
37+
pub(crate) const MAX_MSG_ABSOLUTE: usize = 8972;
3638

3739
// Definitions for DNS message header "flags" field
3840
//

src/service_daemon.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,13 @@ impl Zeroconf {
13861386
None => return false,
13871387
};
13881388
let mut buf = vec![0u8; MAX_MSG_ABSOLUTE];
1389+
1390+
// Read the next mDNS UDP datagram.
1391+
//
1392+
// If the datagram is larger than `buf`, excess bytes may or may not
1393+
// be truncated by the socket layer depending on the platform's libc.
1394+
// In any case, such large datagram will not be decoded properly and
1395+
// this function should return false but should not crash.
13891396
let sz = match intf_sock.sock.read(&mut buf) {
13901397
Ok(sz) => sz,
13911398
Err(e) => {

0 commit comments

Comments
 (0)