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)) {
snmp_set_api_error(SNMPERR_OS_ERR);
PARSE_ERROR;
}
+ int terminatorPos = Var->val_len - 1;
bufp = asn_parse_string(DataPtr, &ThisVarLen,
&Var->type, Var->val.string,
&Var->val_len);
+ if (Var->val_len < terminatorPos) {
+ terminatorPos = Var->val_len;
+ }
+ Var->val.string[terminatorPos] = '\0';
#if DEBUG_VARS_DECODE
printf("VARS: Decoded string '%s' (length %d) (%d bytes left)\n",
(Var->val.string), Var->val_len, ThisVarLen);