[654] Initialise "result" in mosquitto_topic_matches_sub.

Thanks to markhermelinggt.

Bug: https://github.com/eclipse/mosquitto/issues/654
This commit is contained in:
Roger A. Light 2017-12-21 08:36:58 +00:00
parent 7f82cdc753
commit ae666b07ce
2 changed files with 8 additions and 9 deletions

View File

@ -12,6 +12,8 @@ Broker:
Client library: Client library:
- Fix incorrect PSK key being used if it had leading zeroes. - 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: Build:
- Don't run TLS-PSK tests if TLS-PSK disabled at compile time. Closes #636. - Don't run TLS-PSK tests if TLS-PSK disabled at compile time. Closes #636.

View File

@ -228,13 +228,17 @@ int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result
int spos, tpos; int spos, tpos;
bool multilevel_wildcard = false; 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); slen = strlen(sub);
tlen = strlen(topic); tlen = strlen(topic);
if(!slen || !tlen){ if(!slen || !tlen){
*result = false;
return MOSQ_ERR_INVAL; 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] != '$') if((sub[0] == '$' && topic[0] != '$')
|| (topic[0] == '$' && sub[0] != '$')){ || (topic[0] == '$' && sub[0] != '$')){
*result = false;
return MOSQ_ERR_SUCCESS; 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; return MOSQ_ERR_SUCCESS;
}else if(tpos == tlen && spos == slen-1 && sub[spos] == '+'){ }else if(tpos == tlen && spos == slen-1 && sub[spos] == '+'){
if(spos > 0 && sub[spos-1] != '/'){ if(spos > 0 && sub[spos-1] != '/'){
*result = false;
return MOSQ_ERR_INVAL; return MOSQ_ERR_INVAL;
} }
spos++; spos++;
@ -280,12 +282,10 @@ int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result
if(sub[spos] == '+'){ if(sub[spos] == '+'){
/* Check for bad "+foo" or "a/+foo" subscription */ /* Check for bad "+foo" or "a/+foo" subscription */
if(spos > 0 && sub[spos-1] != '/'){ if(spos > 0 && sub[spos-1] != '/'){
*result = false;
return MOSQ_ERR_INVAL; return MOSQ_ERR_INVAL;
} }
/* Check for bad "foo+" or "foo+/a" subscription */ /* Check for bad "foo+" or "foo+/a" subscription */
if(spos < slen-1 && sub[spos+1] != '/'){ if(spos < slen-1 && sub[spos+1] != '/'){
*result = false;
return MOSQ_ERR_INVAL; return MOSQ_ERR_INVAL;
} }
spos++; spos++;
@ -298,19 +298,16 @@ int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result
} }
}else if(sub[spos] == '#'){ }else if(sub[spos] == '#'){
if(spos > 0 && sub[spos-1] != '/'){ if(spos > 0 && sub[spos-1] != '/'){
*result = false;
return MOSQ_ERR_INVAL; return MOSQ_ERR_INVAL;
} }
multilevel_wildcard = true; multilevel_wildcard = true;
if(spos+1 != slen){ if(spos+1 != slen){
*result = false;
return MOSQ_ERR_INVAL; return MOSQ_ERR_INVAL;
}else{ }else{
*result = true; *result = true;
return MOSQ_ERR_SUCCESS; return MOSQ_ERR_SUCCESS;
} }
}else{ }else{
*result = false;
return MOSQ_ERR_SUCCESS; return MOSQ_ERR_SUCCESS;
} }
} }