diff --git a/ChangeLog.txt b/ChangeLog.txt index 55907cef..5628e20a 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -27,6 +27,8 @@ Broker: - Miscellaneous fixes on Windows. - Bridge connections now default to using MQTT v3.1.1. - mosquitto_db_dump tool can now output some stats on clients. +- perform utf-8 validation on incoming will, subscription and unsubscription + topics. Client library: - Outgoing messages with QoS>1 are no longer retried after a timeout period. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index db537c90..876ae1f2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,6 +43,7 @@ set (MOSQ_SRCS ../lib/time_mosq.c ../lib/tls_mosq.c ../lib/util_mosq.c ../lib/util_mosq.h + ../lib/utf8_mosq.c websockets.c ../lib/will_mosq.c ../lib/will_mosq.h) diff --git a/src/Makefile b/src/Makefile index 812feaea..7dccade9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -47,6 +47,7 @@ OBJS= mosquitto.o \ sys_tree.o \ time_mosq.o \ tls_mosq.o \ + utf8_mosq.o \ util_mosq.o \ websockets.o \ will_mosq.o @@ -174,6 +175,9 @@ tls_mosq.o : ../lib/tls_mosq.c util_mosq.o : ../lib/util_mosq.c ../lib/util_mosq.h ${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@ +utf8_mosq.o : ../lib/utf8_mosq.c + ${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@ + websockets.o : websockets.c mosquitto_broker.h ${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@ diff --git a/src/handle_subscribe.c b/src/handle_subscribe.c index 847553ce..13e0757b 100644 --- a/src/handle_subscribe.c +++ b/src/handle_subscribe.c @@ -67,19 +67,28 @@ int handle__subscribe(struct mosquitto_db *db, struct mosquitto *context) if(sub){ if(STREMPTY(sub)){ - log__printf(NULL, MOSQ_LOG_INFO, "Empty subscription string from %s, disconnecting.", - context->address); + log__printf(NULL, MOSQ_LOG_INFO, + "Empty subscription string from %s, disconnecting.", + context->address); mosquitto__free(sub); mosquitto__free(payload); return 1; } if(mosquitto_sub_topic_check(sub)){ - log__printf(NULL, MOSQ_LOG_INFO, "Invalid subscription string from %s, disconnecting.", - context->address); + log__printf(NULL, MOSQ_LOG_INFO, + "Invalid subscription string from %s, disconnecting.", + context->address); mosquitto__free(sub); mosquitto__free(payload); return 1; } + if(mosquitto_validate_utf8(sub, strlen(sub))){ + log__printf(NULL, MOSQ_LOG_INFO, + "Malformed UTF-8 in subscription string from %s, disconnecting.", + context->id); + mosquitto__free(sub); + return 1; + } if(packet__read_byte(&context->in_packet, &qos)){ mosquitto__free(sub); @@ -87,8 +96,9 @@ int handle__subscribe(struct mosquitto_db *db, struct mosquitto *context) return 1; } if(qos > 2){ - log__printf(NULL, MOSQ_LOG_INFO, "Invalid QoS in subscription command from %s, disconnecting.", - context->address); + log__printf(NULL, MOSQ_LOG_INFO, + "Invalid QoS in subscription command from %s, disconnecting.", + context->address); mosquitto__free(sub); mosquitto__free(payload); return 1; diff --git a/src/handle_unsubscribe.c b/src/handle_unsubscribe.c index af7a9587..45c0ea02 100644 --- a/src/handle_unsubscribe.c +++ b/src/handle_unsubscribe.c @@ -54,14 +54,23 @@ int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context) if(sub){ if(STREMPTY(sub)){ - log__printf(NULL, MOSQ_LOG_INFO, "Empty unsubscription string from %s, disconnecting.", - context->id); + log__printf(NULL, MOSQ_LOG_INFO, + "Empty unsubscription string from %s, disconnecting.", + context->id); mosquitto__free(sub); return 1; } if(mosquitto_sub_topic_check(sub)){ - log__printf(NULL, MOSQ_LOG_INFO, "Invalid unsubscription string from %s, disconnecting.", - context->id); + log__printf(NULL, MOSQ_LOG_INFO, + "Invalid unsubscription string from %s, disconnecting.", + context->id); + mosquitto__free(sub); + return 1; + } + if(mosquitto_validate_utf8(sub, strlen(sub))){ + log__printf(NULL, MOSQ_LOG_INFO, + "Malformed UTF-8 in unsubscription string from %s, disconnecting.", + context->id); mosquitto__free(sub); return 1; }