]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
more sanity checks on values
authorAlan T. DeKok <aland@freeradius.org>
Wed, 1 Mar 2023 21:20:53 +0000 (16:20 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 1 Mar 2023 22:29:38 +0000 (17:29 -0500)
src/protocols/bfd/decode.c

index 454657084884564f0e7b923574d4994d1c331072..6d904f8e5d2e759dddc66541930a62d46f110bc3 100644 (file)
@@ -115,10 +115,47 @@ static ssize_t fr_bfd_decode_proto(TALLOC_CTX *ctx, fr_pair_list_t *out,
        packet = (bfd_packet_t const *) data;
 
        if (packet->length > data_len) {
-               fr_strerror_const("Packet.lenth is larger than received data");
+               fr_strerror_const("Packet.length is larger than received data");
                return -1;
        }
 
+       if (packet->length < FR_BFD_HEADER_LENGTH) {
+               fr_strerror_const("Packet.length is smaller then BFD header size");
+               return -1;
+       }
+
+       if (packet->version != 1) {
+               fr_strerror_const("Packet.version has invalid value");
+               return -1;
+       }
+
+       if (packet->detect_multi == 0) {
+               fr_strerror_const("Packet.detect-multi has invalid value zero");
+               return -1;
+       }
+
+       if (packet->detect_multi == 0) {
+               fr_strerror_const("Packet.detect-multi has invalid value zero");
+               return -1;
+       }
+
+       if (packet->multipoint != 0) {
+               fr_strerror_const("Packet.multipoint has invalid non-zero value");
+               return -1;
+       }
+
+       if (packet->my_disc == 0) {
+               fr_strerror_const("Packet.my-discriminator has invalid value zero");
+               return -1;
+       }
+
+       if ((packet->your_disc == 0) &&
+           !((packet->state == BFD_STATE_DOWN) ||
+             (packet->state == BFD_STATE_ADMIN_DOWN))) {
+               fr_strerror_const("Packet has invalid values for your-discriminator and state");
+               return 0;
+       }
+
        /*
         *      Get the packet type.
         */