@@ -453,8 +453,8 @@ static int packet__read_single(struct mosquitto *mosq, enum mosquitto_client_sta
453453#ifdef WITH_BROKER
454454 switch (mosq -> in_packet .command & 0xF0 ){
455455 case CMD_CONNECT :
456- if (mosq -> in_packet .remaining_length > 100000 ){ /* Arbitrary limit, make configurable */
457- return MOSQ_ERR_MALFORMED_PACKET ;
456+ if (mosq -> in_packet .remaining_length > db . config -> packet_max_connect ){
457+ return MOSQ_ERR_OVERSIZE_PACKET ;
458458 }
459459 break ;
460460
@@ -463,8 +463,14 @@ static int packet__read_single(struct mosquitto *mosq, enum mosquitto_client_sta
463463 case CMD_PUBREL :
464464 case CMD_PUBCOMP :
465465 case CMD_UNSUBACK :
466- if (mosq -> protocol != mosq_p_mqtt5 && mosq -> in_packet .remaining_length != 2 ){
467- return MOSQ_ERR_MALFORMED_PACKET ;
466+ if (mosq -> protocol == mosq_p_mqtt5 ){
467+ if (mosq -> in_packet .remaining_length > db .config -> packet_max_simple ){
468+ return MOSQ_ERR_OVERSIZE_PACKET ;
469+ }
470+ }else {
471+ if (mosq -> in_packet .remaining_length != 2 ){
472+ return MOSQ_ERR_MALFORMED_PACKET ;
473+ }
468474 }
469475 break ;
470476
@@ -476,10 +482,30 @@ static int packet__read_single(struct mosquitto *mosq, enum mosquitto_client_sta
476482 break ;
477483
478484 case CMD_DISCONNECT :
479- if (mosq -> protocol != mosq_p_mqtt5 && mosq -> in_packet .remaining_length != 0 ){
480- return MOSQ_ERR_MALFORMED_PACKET ;
485+ if (mosq -> protocol == mosq_p_mqtt5 ){
486+ if (mosq -> in_packet .remaining_length > db .config -> packet_max_simple ){
487+ return MOSQ_ERR_OVERSIZE_PACKET ;
488+ }
489+ }else {
490+ if (mosq -> in_packet .remaining_length != 0 ){
491+ return MOSQ_ERR_MALFORMED_PACKET ;
492+ }
493+ }
494+ break ;
495+
496+ case CMD_SUBSCRIBE :
497+ case CMD_UNSUBSCRIBE :
498+ if (mosq -> protocol == mosq_p_mqtt5 && mosq -> in_packet .remaining_length > db .config -> packet_max_sub ){
499+ return MOSQ_ERR_OVERSIZE_PACKET ;
481500 }
482501 break ;
502+
503+ case CMD_AUTH :
504+ if (mosq -> in_packet .remaining_length > db .config -> packet_max_auth ){
505+ return MOSQ_ERR_OVERSIZE_PACKET ;
506+ }
507+ break ;
508+
483509 }
484510
485511 if (db .config -> max_packet_size > 0 && mosq -> in_packet .remaining_length + 1 > db .config -> max_packet_size ){
0 commit comments