Fix possible null dereferences.

pull/1588/head
Roger A. Light 6 years ago
parent 05ec02b3f3
commit 5528dde56a

@ -498,10 +498,11 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
} }
context = NULL; context = NULL;
HASH_FIND(hh_sock, db->contexts_by_sock, &(ev.data.fd), sizeof(mosq_sock_t), context); HASH_FIND(hh_sock, db->contexts_by_sock, &(ev.data.fd), sizeof(mosq_sock_t), context);
if(!context) { if(context){
context->events = EPOLLIN;
}else{
log__printf(NULL, MOSQ_LOG_ERR, "Error in epoll accepting: no context"); log__printf(NULL, MOSQ_LOG_ERR, "Error in epoll accepting: no context");
} }
context->events = EPOLLIN;
} }
} }
break; break;

@ -216,8 +216,8 @@ static struct sub__token *sub__topic_append(struct sub__token **tail, struct sub
static int sub__topic_tokenise(const char *subtopic, struct sub__token **topics) static int sub__topic_tokenise(const char *subtopic, struct sub__token **topics)
{ {
struct sub__token *new_topic, *tail = NULL; struct sub__token *new_topic, *tail = NULL;
int len; size_t len;
int start, stop, tlen; size_t start, stop, tlen;
int i; int i;
char *topic; char *topic;
int count = 0; int count = 0;
@ -225,13 +225,16 @@ static int sub__topic_tokenise(const char *subtopic, struct sub__token **topics)
assert(subtopic); assert(subtopic);
assert(topics); assert(topics);
len = strlen(subtopic);
if(len == 0){
return 1;
}
if(subtopic[0] != '$'){ if(subtopic[0] != '$'){
new_topic = sub__topic_append(&tail, topics, ""); new_topic = sub__topic_append(&tail, topics, "");
if(!new_topic) goto cleanup; if(!new_topic) goto cleanup;
} }
len = strlen(subtopic);
if(subtopic[0] == '/'){ if(subtopic[0] == '/'){
new_topic = sub__topic_append(&tail, topics, ""); new_topic = sub__topic_append(&tail, topics, "");
if(!new_topic) goto cleanup; if(!new_topic) goto cleanup;
@ -268,7 +271,11 @@ static int sub__topic_tokenise(const char *subtopic, struct sub__token **topics)
goto cleanup; goto cleanup;
} }
return MOSQ_ERR_SUCCESS; if(*topics != NULL){
return MOSQ_ERR_SUCCESS;
}else{
return 1;
}
cleanup: cleanup:
tail = *topics; tail = *topics;

Loading…
Cancel
Save