[654] Initialise "result" in mosquitto_topic_matches_sub.
Thanks to markhermelinggt. Bug: https://github.com/eclipse/mosquitto/issues/654
This commit is contained in:
parent
7f82cdc753
commit
ae666b07ce
@ -12,6 +12,8 @@ Broker:
|
||||
|
||||
Client library:
|
||||
- Fix incorrect PSK key being used if it had leading zeroes.
|
||||
- Initialise "result" variable as soon as possible in
|
||||
mosquitto_topic_matches_sub. Closes #654.
|
||||
|
||||
Build:
|
||||
- Don't run TLS-PSK tests if TLS-PSK disabled at compile time. Closes #636.
|
||||
|
@ -228,13 +228,17 @@ int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result
|
||||
int spos, tpos;
|
||||
bool multilevel_wildcard = false;
|
||||
|
||||
if(!sub || !topic || !result) return MOSQ_ERR_INVAL;
|
||||
if(!result) return MOSQ_ERR_INVAL;
|
||||
*result = false;
|
||||
|
||||
if(!sub || !topic){
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
|
||||
slen = strlen(sub);
|
||||
tlen = strlen(topic);
|
||||
|
||||
if(!slen || !tlen){
|
||||
*result = false;
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
|
||||
@ -242,7 +246,6 @@ int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result
|
||||
if((sub[0] == '$' && topic[0] != '$')
|
||||
|| (topic[0] == '$' && sub[0] != '$')){
|
||||
|
||||
*result = false;
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
}
|
||||
@ -269,7 +272,6 @@ int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}else if(tpos == tlen && spos == slen-1 && sub[spos] == '+'){
|
||||
if(spos > 0 && sub[spos-1] != '/'){
|
||||
*result = false;
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
spos++;
|
||||
@ -280,12 +282,10 @@ int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result
|
||||
if(sub[spos] == '+'){
|
||||
/* Check for bad "+foo" or "a/+foo" subscription */
|
||||
if(spos > 0 && sub[spos-1] != '/'){
|
||||
*result = false;
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
/* Check for bad "foo+" or "foo+/a" subscription */
|
||||
if(spos < slen-1 && sub[spos+1] != '/'){
|
||||
*result = false;
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
spos++;
|
||||
@ -298,19 +298,16 @@ int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result
|
||||
}
|
||||
}else if(sub[spos] == '#'){
|
||||
if(spos > 0 && sub[spos-1] != '/'){
|
||||
*result = false;
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
multilevel_wildcard = true;
|
||||
if(spos+1 != slen){
|
||||
*result = false;
|
||||
return MOSQ_ERR_INVAL;
|
||||
}else{
|
||||
*result = true;
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
}else{
|
||||
*result = false;
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user