@@ -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,7 +463,9 @@ 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 ){
466+ if (mosq -> protocol == mosq_p_mqtt5 && mosq -> in_packet .remaining_length > db .config -> packet_max_simple ){
467+ return MOSQ_ERR_OVERSIZE_PACKET ;
468+ }else if (mosq -> in_packet .remaining_length != 2 ){
467469 return MOSQ_ERR_MALFORMED_PACKET ;
468470 }
469471 break ;
@@ -476,10 +478,26 @@ static int packet__read_single(struct mosquitto *mosq, enum mosquitto_client_sta
476478 break ;
477479
478480 case CMD_DISCONNECT :
479- if (mosq -> protocol != mosq_p_mqtt5 && mosq -> in_packet .remaining_length != 0 ){
481+ if (mosq -> protocol == mosq_p_mqtt5 && mosq -> in_packet .remaining_length > db .config -> packet_max_simple ){
482+ return MOSQ_ERR_OVERSIZE_PACKET ;
483+ }else if (mosq -> in_packet .remaining_length != 0 ){
480484 return MOSQ_ERR_MALFORMED_PACKET ;
481485 }
482486 break ;
487+
488+ case CMD_SUBSCRIBE :
489+ case CMD_UNSUBSCRIBE :
490+ if (mosq -> protocol == mosq_p_mqtt5 && mosq -> in_packet .remaining_length > db .config -> packet_max_sub ){
491+ return MOSQ_ERR_OVERSIZE_PACKET ;
492+ }
493+ break ;
494+
495+ case CMD_AUTH :
496+ if (mosq -> in_packet .remaining_length > db .config -> packet_max_auth ){
497+ return MOSQ_ERR_OVERSIZE_PACKET ;
498+ }
499+ break ;
500+
483501 }
484502
485503 if (db .config -> max_packet_size > 0 && mosq -> in_packet .remaining_length + 1 > db .config -> max_packet_size ){
0 commit comments