]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - lib/snmplib/snmp_msg.c
Source Format Enforcement (#763)
[thirdparty/squid.git] / lib / snmplib / snmp_msg.c
index 0820b064e75c8228592502dd600c78e6ec7bf048..6845a7547c5e2aa93bdd1e4d33928c531941a7db 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
@@ -272,12 +272,16 @@ snmp_msg_Decode(u_char * Packet, int *PacketLenP,
         snmplib_debug(4, "snmp_msg_Decode:Error decoding SNMP Message Header (Version)!\n");
         ASN_PARSE_ERROR(NULL);
     }
+    int terminatorPos = *CommLenP - 1;
     bufp = asn_parse_string(bufp, PacketLenP, &type, Community, CommLenP);
     if (bufp == NULL) {
         snmplib_debug(4, "snmp_msg_Decode:Error decoding SNMP Message Header (Community)!\n");
         ASN_PARSE_ERROR(NULL);
     }
-    Community[*CommLenP] = '\0';
+    if (*CommLenP < terminatorPos) {
+        terminatorPos = *CommLenP;
+    }
+    Community[terminatorPos] = '\0';
 
     if ((*Version != SNMP_VERSION_1) &&
             (*Version != SNMP_VERSION_2)) {