From 9b08faf0bdaf5a4f2e6e3dd1ea7e8c57f70418d6 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 9 Feb 2021 14:09:53 +0000 Subject: [PATCH] Fix mosquitto_{pub|sub}_topic_check() function returns. The would not return MOSQ_ERR_INVAL on topic == NULL. --- ChangeLog.txt | 5 +++++ lib/util_topic.c | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 214974b0..33457bbd 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -8,10 +8,15 @@ Broker: - Give compile time warning if libwebsockets compiled without external poll support. Closes #2060. +Client library: +- Fix mosquitto_{pub|sub}_topic_check() functions not returning MOSQ_ERR_INVAL + on topic == NULL. + Clients: - Fix possible loss of data in `mosquitto_pub -l` when sending multiple long lines. Closes #2078. + 2.0.7 - 2021-02-04 ================== diff --git a/lib/util_topic.c b/lib/util_topic.c index fc24f0d1..62b53112 100644 --- a/lib/util_topic.c +++ b/lib/util_topic.c @@ -54,6 +54,11 @@ int mosquitto_pub_topic_check(const char *str) #ifdef WITH_BROKER int hier_count = 0; #endif + + if(str == NULL){ + return MOSQ_ERR_INVAL; + } + while(str && str[0]){ if(str[0] == '+' || str[0] == '#'){ return MOSQ_ERR_INVAL; @@ -81,7 +86,9 @@ int mosquitto_pub_topic_check2(const char *str, size_t len) int hier_count = 0; #endif - if(len > 65535) return MOSQ_ERR_INVAL; + if(str == NULL || len > 65535){ + return MOSQ_ERR_INVAL; + } for(i=0; i 65535) return MOSQ_ERR_INVAL; + if(str == NULL || len > 65535){ + return MOSQ_ERR_INVAL; + } for(i=0; i