Blame SOURCES/net-snmp-5.8-bulk.patch

17224f
diff -urNp a/snmplib/snmp_api.c b/snmplib/snmp_api.c
17224f
--- a/snmplib/snmp_api.c	2020-09-29 14:08:09.821479662 +0200
17224f
+++ b/snmplib/snmp_api.c	2020-10-01 10:15:46.607374362 +0200
17224f
@@ -769,7 +769,7 @@ snmp_sess_init(netsnmp_session * session
17224f
     session->retries = SNMP_DEFAULT_RETRIES;
17224f
     session->version = SNMP_DEFAULT_VERSION;
17224f
     session->securityModel = SNMP_DEFAULT_SECMODEL;
17224f
-    session->rcvMsgMaxSize = SNMP_MAX_MSG_SIZE;
17224f
+    session->rcvMsgMaxSize = netsnmp_max_send_msg_size();
17224f
     session->sndMsgMaxSize = netsnmp_max_send_msg_size();
17224f
     session->flags |= SNMP_FLAGS_DONT_PROBE;
17224f
 }
17224f
@@ -2731,7 +2731,7 @@ snmpv3_packet_build(netsnmp_session * se
17224f
     /*
17224f
      * build a scopedPDU structure into spdu_buf
17224f
      */
17224f
-    spdu_buf_len = SNMP_MAX_MSG_SIZE;
17224f
+    spdu_buf_len = sizeof(spdu_buf);
17224f
     DEBUGDUMPSECTION("send", "ScopedPdu");
17224f
     cp = snmpv3_scopedPDU_header_build(pdu, spdu_buf, &spdu_buf_len,
17224f
                                        &spdu_hdr_e);
17224f
@@ -2743,6 +2743,11 @@ snmpv3_packet_build(netsnmp_session * se
17224f
      */
17224f
     DEBUGPRINTPDUTYPE("send", ((pdu_data) ? *pdu_data : 0x00));
17224f
     if (pdu_data) {
17224f
+        if (cp + pdu_data_len > spdu_buf + sizeof(spdu_buf)) {
17224f
+            snmp_log(LOG_ERR, "%s: PDU too big (%" NETSNMP_PRIz "d > %" NETSNMP_PRIz "d)\n",
17224f
+                     __func__, pdu_data_len, sizeof(spdu_buf));
17224f
+            return -1;
17224f
+        }
17224f
         memcpy(cp, pdu_data, pdu_data_len);
17224f
         cp += pdu_data_len;
17224f
     } else {
17224f
@@ -2756,7 +2761,7 @@ snmpv3_packet_build(netsnmp_session * se
17224f
      * re-encode the actual ASN.1 length of the scopedPdu
17224f
      */
17224f
     spdu_len = cp - spdu_hdr_e; /* length of scopedPdu minus ASN.1 headers */
17224f
-    spdu_buf_len = SNMP_MAX_MSG_SIZE;
17224f
+    spdu_buf_len = sizeof(spdu_buf);
17224f
     if (asn_build_sequence(spdu_buf, &spdu_buf_len,
17224f
                            (u_char) (ASN_SEQUENCE | ASN_CONSTRUCTOR),
17224f
                            spdu_len) == NULL)
17224f
@@ -2769,7 +2774,7 @@ snmpv3_packet_build(netsnmp_session * se
17224f
      * message - the entire message to transmitted on the wire is returned
17224f
      */
17224f
     cp = NULL;
17224f
-    *out_length = SNMP_MAX_MSG_SIZE;
17224f
+    *out_length = sizeof(spdu_buf);
17224f
     DEBUGDUMPSECTION("send", "SM msgSecurityParameters");
17224f
     sptr = find_sec_mod(pdu->securityModel);
17224f
     if (sptr && sptr->encode_forward) {