_daveSetupReceivedPDU in nodave.c computes p->plen/p->dlen from the S7
response header (up to 65535 each) and sets p->data = p->param + p->plen with
no check against the received length, so p->data can point far past the fixed
2048-byte msgIn buffer. The result handlers then dereference it:
p->plen = 256*p->header[6] + p->header[7];
p->data = p->param + p->plen; // no bound vs received length
...
if ((p->data[0]==255) && (p->dlen>4)) // _daveTestResultData: OOB read
A malicious/compromised S7 PLC (or MITM) returning a crafted response to a
libnodave client triggers the OOB read.
Remote, unauthenticated out-of-bounds read: DoS and potential information
disclosure (leaked bytes can flow back via the result). Distinct from the
_daveReadISOPacket overflow (bug reported separately).
A response with plen=0xFFFF produces, under AddressSanitizer, a
heap-buffer-overflow READ in _daveTestResultData (nodave.c:702). Reproducer
available on request.
Validate hlen+plen+dlen against the received length (dc->AnswLen) before
setting p->data/p->dlen, and bound subsequent accesses.
Reporter: Gyu-hyun Jeon, STEALIEN