From 23421b47d998c6fc4f90070c34c0693362d95bed Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Wed, 18 Dec 2019 19:49:46 +0100 Subject: Added snprintf() return code check --- src/lib/protocols/dhcp.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/lib/protocols/dhcp.c') diff --git a/src/lib/protocols/dhcp.c b/src/lib/protocols/dhcp.c index 2aff1ec18..d939df1d8 100644 --- a/src/lib/protocols/dhcp.c +++ b/src/lib/protocols/dhcp.c @@ -104,16 +104,12 @@ void ndpi_search_dhcp_udp(struct ndpi_detection_module_struct *ndpi_struct, stru u_int idx, offset = 0; for(idx = 0; idx < len && offset < sizeof(flow->protos.dhcp.fingerprint) - 2; idx++) { -#if 1 - offset += snprintf((char*)&flow->protos.dhcp.fingerprint[offset], + int rc = snprintf((char*)&flow->protos.dhcp.fingerprint[offset], sizeof(flow->protos.dhcp.fingerprint) - offset, "%s%u", (idx > 0) ? "," : "", (unsigned int)dhcp->options[i+2+idx] & 0xFF); -#else - offset += snprintf((char*)&flow->protos.dhcp.fingerprint[offset], - sizeof(flow->protos.dhcp.fingerprint) - offset, - "%02X", dhcp->options[i+2+idx] & 0xFF); -#endif + + if(rc < 0) break; else offset += rc; } flow->protos.dhcp.fingerprint[sizeof(flow->protos.dhcp.fingerprint) - 1] = '\0'; -- cgit v1.2.3