Changeset 464 for azure_iot_hub_f767zi/trunk/azure_iot_sdk/umqtt/src
- Timestamp:
- Jun 22, 2021, 9:00:19 PM (3 years ago)
- Location:
- azure_iot_hub_f767zi/trunk/azure_iot_sdk/umqtt/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
azure_iot_hub_f767zi/trunk/azure_iot_sdk/umqtt/src/mqtt_client.c
r457 r464 770 770 /*Codes_SRS_MQTT_CLIENT_07_028: [If the actionResult parameter is of type CONNECT_ACK then the msgInfo value shall be a CONNECT_ACK structure.]*/ 771 771 CONNECT_ACK connack = { 0 }; 772 connack.isSessionPresent = (byteutil_readByte(&iterator) == 0x1) ? true : false; 772 if (packetLength != 2) // CONNACK payload must be only 2 bytes 773 { 774 LogError("Invalid CONNACK packet."); 775 set_error_callback(mqtt_client, MQTT_CLIENT_COMMUNICATION_ERROR); 776 break; 777 } 778 779 uint8_t connect_acknowledge_flags = byteutil_readByte(&iterator); 780 if (connect_acknowledge_flags & 0xFE) // bits 7-1 must be zero 781 { 782 LogError("Invalid CONNACK packet."); 783 set_error_callback(mqtt_client, MQTT_CLIENT_COMMUNICATION_ERROR); 784 break; 785 } 786 787 connack.isSessionPresent = (connect_acknowledge_flags == 0x1) ? true : false; 773 788 uint8_t rc = byteutil_readByte(&iterator); 774 789 connack.returnCode = … … 802 817 case PUBCOMP_TYPE: 803 818 { 819 if (packetLength != 2) // PUBXXX payload must be only 2 bytes 820 { 821 LogError("Invalid packet length."); 822 set_error_callback(mqtt_client, MQTT_CLIENT_COMMUNICATION_ERROR); 823 break; 824 } 825 804 826 /*Codes_SRS_MQTT_CLIENT_07_029: [If the actionResult parameter are of types PUBACK_TYPE, PUBREC_TYPE, PUBREL_TYPE or PUBCOMP_TYPE then the msgInfo value shall be a PUBLISH_ACK structure.]*/ 805 827 MQTT_CLIENT_EVENT_RESULT action = (packet == PUBACK_TYPE) ? MQTT_CLIENT_ON_PUBLISH_ACK : … … 876 898 { 877 899 uint8_t qosRet = byteutil_readByte(&iterator); 900 if (qosRet & 0x7C) // SUBACK QOS bits 6-2 must be zero 901 { 902 LogError("Invalid SUBACK_TYPE packet."); 903 set_error_callback(mqtt_client, MQTT_CLIENT_COMMUNICATION_ERROR); 904 break; 905 } 878 906 suback.qosReturn[suback.qosCount++] = 879 907 (qosRet <= ((uint8_t)DELIVER_EXACTLY_ONCE)) ? … … 909 937 /*Codes_SRS_MQTT_CLIENT_07_031: [If the actionResult parameter is of type UNSUBACK_TYPE then the msgInfo value shall be a UNSUBSCRIBE_ACK structure.]*/ 910 938 UNSUBSCRIBE_ACK unsuback = { 0 }; 939 if (packetLength != 2) // UNSUBACK_TYPE payload must be only 2 bytes 940 { 941 LogError("Invalid UNSUBACK packet length."); 942 set_error_callback(mqtt_client, MQTT_CLIENT_COMMUNICATION_ERROR); 943 break; 944 } 945 911 946 unsuback.packetId = byteutil_read_uint16(&iterator, packetLength); 912 947 … … 943 978 { 944 979 LogError("recvCompleteCallback context failed."); 980 } 981 } 982 983 void mqtt_client_clear_xio(MQTT_CLIENT_HANDLE handle) 984 { 985 if (handle != NULL) 986 { 987 MQTT_CLIENT *mqtt_client = (MQTT_CLIENT *)handle; 988 989 // The upstream transport handle allocates and deallocates the xio handle. 990 // The reference to that xio handle is shared between this layer (mqtt layer) 991 // and the upstream layer. The clearing done here is to signal to this layer 992 // that the handle is no longer available to be used. This is different from 993 // deiniting the mqtt client in that we do not want an entire teardown, but 994 // only a possible re-upping of the xio in the future. 995 mqtt_client->xioHandle = NULL; 945 996 } 946 997 } -
azure_iot_hub_f767zi/trunk/azure_iot_sdk/umqtt/src/mqtt_codec.c
r457 r464 568 568 } 569 569 } 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; 570 580 } 571 581 return result; … … 1067 1077 { 1068 1078 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 } 1069 1122 } 1070 1123 else … … 1078 1131 else if (codec_Data->currPacket == PINGRESP_TYPE) 1079 1132 { 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 } 1082 1144 } 1083 1145 }
Note:
See TracChangeset
for help on using the changeset viewer.