+/*
+ * 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.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
/*
* SNMP Message Encoding Routines
*
#include "squid.h"
-#include <stdio.h>
-
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
PDUDataStart = bufp;
bufp = snmp_pdu_encode(bufp, BufLenP, PDU);
if (bufp == NULL)
- return (NULL); /* snmp_pdu_encode registered failure */
+ return (NULL); /* snmp_pdu_encode registered failure */
VARHeaderPtr = bufp;
bufp = asn_build_header(bufp, BufLenP,
/* And build the variables */
bufp = snmp_var_EncodeVarBind(bufp, BufLenP, PDU->variables, Version);
if (bufp == NULL)
- return (NULL); /* snmp_var_EncodeVarBind registered failure */
+ return (NULL); /* snmp_var_EncodeVarBind registered failure */
/* Cool. Now insert the appropriate lengths.
*/
tmp = asn_build_header(Buffer,
&FakeArg,
(u_char) (ASN_SEQUENCE | ASN_CONSTRUCTOR),
- (bufp - MsgPtr)); /* Length of everything */
+ (bufp - MsgPtr)); /* Length of everything */
if (tmp == NULL)
return (NULL);
tmp = asn_build_header(VARHeaderPtr,
&FakeArg,
(u_char) (ASN_SEQUENCE | ASN_CONSTRUCTOR),
- (bufp - VARDataStart)); /* Length of everything */
+ (bufp - VARDataStart)); /* Length of everything */
if (tmp == NULL)
return (NULL);
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)) {
return (u_char *) bufp;
}
+