From 2673e635a304c7cebc93cdca3824b9a377e08709 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 30 Mar 2017 11:09:35 +0200 Subject: [PATCH] Fix community string length copying - correctly handle long strings --- src/apps/snmp/snmp_msg.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/apps/snmp/snmp_msg.c b/src/apps/snmp/snmp_msg.c index 1107464c..7d6eefd1 100644 --- a/src/apps/snmp/snmp_msg.c +++ b/src/apps/snmp/snmp_msg.c @@ -821,8 +821,9 @@ snmp_parse_inbound_frame(struct snmp_request *request) /* SNMPv3 doesn't use communities */ /* @todo: Differentiate read/write access */ - strncpy((char*)request->community, snmp_community, sizeof(request->community)); - request->community_strlen = (u16_t)strnlen((char*)request->community, sizeof(request->community)); + strncpy((char*)request->community, snmp_community, SNMP_MAX_COMMUNITY_STR_LEN); + request->community[SNMP_MAX_COMMUNITY_STR_LEN] = 0; /* ensure NULL termination (strncpy does NOT guarantee it!) */ + request->community_strlen = (u16_t)strnlen((char*)request->community, SNMP_MAX_COMMUNITY_STR_LEN); /* RFC3414 globalData */ IF_PARSE_EXEC(snmp_asn1_dec_tlv(&pbuf_stream, &tlv));