Skip to content

Commit

Permalink
Report invalid bridge prefix+pattern combinations at config parsing time
Browse files Browse the repository at this point in the history
Rather than letting the bridge fail later.

Issue #1635. Thanks to pokerazor.
  • Loading branch information
ralight committed Mar 28, 2020
1 parent 4ab0f4b commit de25ff6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.txt
@@ -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.

Expand Down
32 changes: 28 additions & 4 deletions src/conf.c
Expand Up @@ -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);
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit de25ff6

Please sign in to comment.