mesh: provisionee: Handle unknown PDUs
authorIsak Westin <isak.westin@loytec.com>
Thu, 6 Oct 2022 14:59:23 +0000 (16:59 +0200)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:55 +0000 (14:55 +0530)
If an unknown PDU is received during provisioning, the provisioning
should fail with "Invalid PDU".

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
mesh/prov-acceptor.c

index f579a14..ac257b1 100644 (file)
@@ -399,6 +399,12 @@ static void acp_prov_rx(void *user_data, const uint8_t *data, uint16_t len)
        l_debug("Provisioning packet received type: %2.2x (%u octets)",
                                                                type, len);
 
+       if (type >= L_ARRAY_SIZE(expected_pdu_size)) {
+               l_error("Unknown PDU type: %2.2x", type);
+               fail.reason = PROV_ERR_INVALID_PDU;
+               goto failure;
+       }
+
        if (type == prov->previous) {
                l_error("Ignore repeated %2.2x packet", type);
                return;
@@ -408,8 +414,7 @@ static void acp_prov_rx(void *user_data, const uint8_t *data, uint16_t len)
                goto failure;
        }
 
-       if (type >= L_ARRAY_SIZE(expected_pdu_size) ||
-                                       len != expected_pdu_size[type]) {
+       if (len != expected_pdu_size[type]) {
                l_error("Expected PDU size %d, Got %d (type: %2.2x)",
                        len, expected_pdu_size[type], type);
                fail.reason = PROV_ERR_INVALID_FORMAT;