Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow topic to be encapsulated in quotes #3174

Open
wants to merge 1 commit into
base: fixes
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2052,12 +2052,33 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload,
}

token = strtok_r(NULL, " ", &saveptr);
if(token){

// Check if the topic is quoted (e.g. for spaces within topic names)
if(token && token[0] == '"') {
if (strchr(saveptr, '"') == NULL) {
log__printf(NULL, MOSQ_LOG_ERR, "Error: Missing closing quote in topic value (%s).", saveptr);
return MOSQ_ERR_INVAL;
}

char *topicInQuotes = strtok_r(NULL, "\"", &saveptr);

topic = mosquitto__malloc(strlen(token) + strlen(topicInQuotes) + 1);
if (!topic) {
log__printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory.");
return MOSQ_ERR_NOMEM;
}

strcpy(topic, token + 1);
strcat(topic, " ");
strcat(topic, topicInQuotes);

}else if(token){
topic = token;
}else{
log__printf(NULL, MOSQ_LOG_ERR, "Error: Empty topic value in configuration.");
return MOSQ_ERR_INVAL;
}

token = strtok_r(NULL, " ", &saveptr);
if(token){
if(!strcasecmp(token, "out")){
Expand Down Expand Up @@ -2399,4 +2420,4 @@ static int conf__parse_string(char **token, const char *name, char **value, char
return MOSQ_ERR_INVAL;
}
return MOSQ_ERR_SUCCESS;
}
}