Ignore:
Timestamp:
Jun 22, 2021, 9:00:19 PM (3 years ago)
Author:
coas-nagasima
Message:

WolfSSLとAzure IoT SDKを更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/umqtt/src/mqtt_codec.c

    r457 r464  
    568568            }
    569569        }
     570    }
     571    else if (codecData->remainLenIndex == (sizeof(codecData->storeRemainLen) / sizeof(codecData->storeRemainLen[0])))
     572    {
     573        // The maximum number of bytes in the Remaining Length field is four
     574        // This allows applications to send Control Packets of size up to 268,435,455 (256 MB).
     575        // The representation of this number on the wire is: 0xFF, 0xFF, 0xFF, 0x7F.
     576
     577        // The last byte has exceed the max value of 0x7F
     578        LogError("MQTT packet len is invalid");
     579        result = MU_FAILURE;
    570580    }
    571581    return result;
     
    10671077                {
    10681078                    codec_Data->currPacket = processControlPacketType(iterator, &codec_Data->headerFlags);
     1079
     1080                    // validate packet type and invalid reserved header flags
     1081                    switch (codec_Data->currPacket)
     1082                    {
     1083                        case PACKET_INVALID1_TYPE:
     1084                        case PACKET_INVALID2_TYPE:
     1085                            codec_Data->currPacket = PACKET_TYPE_ERROR;
     1086                            result = MU_FAILURE;
     1087                            break;
     1088
     1089                        case CONNECT_TYPE:
     1090                        case CONNACK_TYPE:
     1091                        case PUBACK_TYPE:
     1092                        case PUBREC_TYPE:
     1093                        case PUBCOMP_TYPE:
     1094                        case SUBACK_TYPE:
     1095                        case UNSUBACK_TYPE:
     1096                        case PINGREQ_TYPE:
     1097                        case PINGRESP_TYPE:
     1098                        case DISCONNECT_TYPE:
     1099                            if (codec_Data->headerFlags & 0x0F) // flags must be all zeros
     1100                            {
     1101                                codec_Data->currPacket = PACKET_TYPE_ERROR;
     1102                                result = MU_FAILURE;
     1103                            }
     1104                            break;
     1105
     1106                        case PUBREL_TYPE:
     1107                        case SUBSCRIBE_TYPE:
     1108                        case UNSUBSCRIBE_TYPE:
     1109                            if ((codec_Data->headerFlags & 0x0F) != 0x02) // only bit 1 must be set
     1110                            {
     1111                                codec_Data->currPacket = PACKET_TYPE_ERROR;
     1112                                result = MU_FAILURE;
     1113                            }
     1114                            break;
     1115
     1116                        case PUBLISH_TYPE:
     1117                        case CONTROL_PACKET_TYPE_INVALID:
     1118                        case PACKET_TYPE_ERROR:
     1119                        case UNKNOWN_TYPE:
     1120                            break;
     1121                    }
    10691122                }
    10701123                else
     
    10781131                    else if (codec_Data->currPacket == PINGRESP_TYPE)
    10791132                    {
    1080                         /* Codes_SRS_MQTT_CODEC_07_034: [Upon a constructing a complete MQTT packet mqtt_codec_bytesReceived shall call the ON_PACKET_COMPLETE_CALLBACK function.] */
    1081                         completePacketData(codec_Data);
     1133                        // PINGRESP must not have a payload
     1134                        if (((int8_t*)buffer)[index] == 0)
     1135                        {
     1136                            /* Codes_SRS_MQTT_CODEC_07_034: [Upon a constructing a complete MQTT packet mqtt_codec_bytesReceived shall call the ON_PACKET_COMPLETE_CALLBACK function.] */
     1137                            completePacketData(codec_Data);
     1138                        }
     1139                        else
     1140                        {
     1141                            codec_Data->currPacket = PACKET_TYPE_ERROR;
     1142                            result = MU_FAILURE;
     1143                        }
    10821144                    }
    10831145                }
Note: See TracChangeset for help on using the changeset viewer.