Skip to content

Commit

Permalink
Fix mosquitto_{pub|sub}_topic_check() function returns.
Browse files Browse the repository at this point in the history
The would not return MOSQ_ERR_INVAL on topic == NULL.
  • Loading branch information
ralight committed Feb 9, 2021
1 parent 1b24f62 commit 9b08faf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
==================

Expand Down
19 changes: 16 additions & 3 deletions lib/util_topic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<len; i++){
if(str[i] == '+' || str[i] == '#'){
Expand Down Expand Up @@ -115,7 +122,11 @@ int mosquitto_sub_topic_check(const char *str)
int hier_count = 0;
#endif

while(str && str[0]){
if(str == NULL){
return MOSQ_ERR_INVAL;
}

while(str[0]){
if(str[0] == '+'){
if((c != '\0' && c != '/') || (str[1] != '\0' && str[1] != '/')){
return MOSQ_ERR_INVAL;
Expand Down Expand Up @@ -150,7 +161,9 @@ int mosquitto_sub_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<len; i++){
if(str[i] == '+'){
Expand Down

0 comments on commit 9b08faf

Please sign in to comment.