@@ -101,6 +101,9 @@ static uint64_t dnp3_max_tx = 32;
101101/* The maximum number of points allowed per message (configurable). */
102102static uint64_t max_points = 16384 ;
103103
104+ /* The maximum number of objects allowed per message (configurable). */
105+ static uint64_t dnp3_max_objects = 2048 ;
106+
104107/* Decoder event map. */
105108SCEnumCharMap dnp3_decoder_event_table [] = {
106109 { "FLOODED" , DNP3_DECODER_EVENT_FLOODED },
@@ -110,6 +113,7 @@ SCEnumCharMap dnp3_decoder_event_table[] = {
110113 { "MALFORMED" , DNP3_DECODER_EVENT_MALFORMED },
111114 { "UNKNOWN_OBJECT" , DNP3_DECODER_EVENT_UNKNOWN_OBJECT },
112115 { "TOO_MANY_POINTS" , DNP3_DECODER_EVENT_TOO_MANY_POINTS },
116+ { "TOO_MANY_OBJECTS" , DNP3_DECODER_EVENT_TOO_MANY_OBJECTS },
113117 { NULL , -1 },
114118};
115119
@@ -714,6 +718,7 @@ static int DNP3DecodeApplicationObjects(DNP3Transaction *tx, const uint8_t *buf,
714718{
715719 int retval = 0 ;
716720 uint64_t point_count = 0 ;
721+ uint64_t object_count = 0 ;
717722
718723 if (buf == NULL || len == 0 ) {
719724 return 1 ;
@@ -728,6 +733,12 @@ static int DNP3DecodeApplicationObjects(DNP3Transaction *tx, const uint8_t *buf,
728733 DNP3ObjHeader * header = (DNP3ObjHeader * )buf ;
729734 offset += sizeof (DNP3ObjHeader );
730735
736+ /* Check if we've exceeded the maximum number of objects. */
737+ if (++ object_count > dnp3_max_objects ) {
738+ DNP3SetEventTx (tx , DNP3_DECODER_EVENT_TOO_MANY_OBJECTS );
739+ goto done ;
740+ }
741+
731742 DNP3Object * object = DNP3ObjectAlloc ();
732743 if (unlikely (object == NULL )) {
733744 goto done ;
@@ -1635,6 +1646,13 @@ void RegisterDNP3Parsers(void)
16351646 max_points = (uint64_t )value ;
16361647 }
16371648 }
1649+
1650+ /* Parse max-objects configuration. */
1651+ if (ConfGetInt ("app-layer.protocols.dnp3.max-objects" , & value )) {
1652+ if (value > 0 ) {
1653+ dnp3_max_objects = (uint64_t )value ;
1654+ }
1655+ }
16381656 } else {
16391657 SCLogConfig ("Parser disabled for protocol %s. "
16401658 "Protocol detection still on." , proto_name );
0 commit comments