Perform UTF-8 validation on will, sub, unsub topics in the broker.

pull/207/head
Roger A. Light 9 years ago
parent a8a5daf06b
commit 63e3926987

@ -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.

@ -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)

@ -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 $@

@ -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;

@ -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;
}

Loading…
Cancel
Save