smb1: bound dialect count in NEGOTIATE_PROTOCOL parser

Negotiate protocol parser used an unbounded many1(complete(...))
combinator over the entire remaining packet input, discarding both
wct and bcc fields. Each NUL byte yielded one empty "dialect" entry,
causing excessive memory use.

Use bcc to limit the parsing; the dialect count is then bounded by
bcc (u16).

Ticket: #8852.
(cherry picked from commit ba1cafd34e)
pull/16211/head
Victor Julien 3 months ago committed by Jason Ish
parent a8f1b5b5bd
commit 2d47fb1494

@ -198,10 +198,12 @@ pub struct Smb1NegotiateProtocolRecord<'a> {
pub fn parse_smb1_negotiate_protocol_record(i: &[u8])
-> IResult<&[u8], Smb1NegotiateProtocolRecord<'_>> {
let (i, _wtc) = le_u8(i)?;
let (i, _bcc) = le_u16(i)?;
let (i, _wct) = le_u8(i)?;
let (i, bcc) = le_u16(i)?;
// dialects is a list of [1 byte buffer format][string][0 terminator]
let (i, dialects) = many1(complete(take_until_and_consume(b"\0")))(i)?;
// honour ByteCount to avoid unbounded allocation
let (i, payload) = take(bcc as usize)(i)?;
let (_, dialects) = many1(complete(take_until_and_consume(b"\0")))(payload)?;
let record = Smb1NegotiateProtocolRecord { dialects };
Ok((i, record))
}

Loading…
Cancel
Save