Report invalid bridge prefix+pattern combinations at config parsing time

Rather than letting the bridge fail later.

Issue #1635. Thanks to pokerazor.
This commit is contained in:
Roger A. Light 2020-03-28 22:39:56 +00:00
parent 4ab0f4bd39
commit de25ff694e
2 changed files with 32 additions and 4 deletions

View File

@ -1,3 +1,7 @@
Broker:
- Report invalid bridge prefix+pattern combinations at config parsing time
rather than letting the bridge fail later. Issue #1635.
Client library:
- Don't treat an unexpected PUBREL as a fatal error. Issue #1629.

View File

@ -2021,11 +2021,22 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge topic local prefix '%s'.", token);
return MOSQ_ERR_INVAL;
}
cur_topic->local_prefix = mosquitto__strdup(token);
if(!cur_topic->local_prefix){
cur_topic->local_prefix = malloc(strlen(cur_topic->topic) + strlen(token) + 1);
if(cur_topic == NULL){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory.");
return MOSQ_ERR_NOMEM;
}
/* Print prefix+pattern to check for validity */
snprintf(cur_topic->local_prefix, strlen(cur_topic->topic) + strlen(token)+1,
"%s%s", token, cur_topic->topic);
if(mosquitto_sub_topic_check(cur_topic->local_prefix) != MOSQ_ERR_SUCCESS){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge topic local prefix and pattern combination '%s'.", cur_topic->local_prefix);
return MOSQ_ERR_INVAL;
}
/* Print just the prefix for storage */
snprintf(cur_topic->local_prefix, strlen(cur_topic->topic) + strlen(token)+1,
"%s", token);
}
token = strtok_r(NULL, " ", &saveptr);
@ -2037,11 +2048,24 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge topic remote prefix '%s'.", token);
return MOSQ_ERR_INVAL;
}
cur_topic->remote_prefix = mosquitto__strdup(token);
if(!cur_topic->remote_prefix){
cur_topic->remote_prefix = malloc(strlen(cur_topic->topic) + strlen(token) + 1);
if(cur_topic == NULL){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory.");
return MOSQ_ERR_NOMEM;
}
/* Print prefix+pattern to check for validity */
snprintf(cur_topic->remote_prefix, strlen(cur_topic->topic) + strlen(token)+1,
"%s%s", token, cur_topic->topic);
if(mosquitto_sub_topic_check(cur_topic->remote_prefix) != MOSQ_ERR_SUCCESS){
log__printf(NULL, MOSQ_LOG_ERR,
"Error: Invalid bridge topic remote prefix and pattern combination '%s'.",
cur_topic->remote_prefix);
return MOSQ_ERR_INVAL;
}
/* Print just the prefix for storage */
snprintf(cur_topic->remote_prefix, strlen(cur_topic->topic) + strlen(token)+1,
"%s", token);
}
}
}