Skip to content

Commit

Permalink
Coverity Scan issues.
Browse files Browse the repository at this point in the history
1436823
1436837
1436843
1432792
1436847
1436848
1436849
  • Loading branch information
ralight committed Nov 24, 2020
1 parent f83fcc8 commit 0c63657
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
19 changes: 14 additions & 5 deletions apps/db_dump/db_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,15 @@ static int dump__msg_store_chunk_process(FILE *db_fptr, uint32_t length)
}

stored = mosquitto__calloc(1, sizeof(struct mosquitto_msg_store));
if(stored == NULL){
mosquitto__free(load);
fclose(db_fptr);
mosquitto__free(chunk.source.id);
mosquitto__free(chunk.source.username);
mosquitto__free(chunk.topic);
UHPA_FREE(chunk.payload, chunk.F.payloadlen);
return MOSQ_ERR_NOMEM;
}
stored->source_mid = chunk.F.source_mid;
stored->topic = chunk.topic;
stored->qos = chunk.F.qos;
Expand All @@ -286,12 +295,9 @@ static int dump__msg_store_chunk_process(FILE *db_fptr, uint32_t length)
chunk.source.username = NULL;

if(rc == MOSQ_ERR_SUCCESS){
/*
printf("stored:%p\n", stored);
stored->source_listener = chunk.source.listener;
load->db_id = stored->db_id;
load->store = stored;
*/

HASH_ADD(hh, db.msg_store_load, db_id, sizeof(dbid_t), load);
}else{
Expand Down Expand Up @@ -455,7 +461,10 @@ int main(int argc, char *argv[])

default:
fprintf(stderr, "Warning: Unsupported chunk \"%d\" in persistent database file. Ignoring.\n", chunk);
fseek(fd, length, SEEK_CUR);
if(fseek(fd, length, SEEK_CUR) < 0){
fprintf(stderr, "Error seeking in file.\n");
return 1;
}
break;
}
}
Expand Down Expand Up @@ -486,7 +495,7 @@ int main(int argc, char *argv[])
return rc;
error:
fprintf(stderr, "Error: %s.", strerror(errno));
if(fd >= 0) fclose(fd);
if(fd) fclose(fd);
return 1;
}

16 changes: 9 additions & 7 deletions apps/mosquitto_passwd/mosquitto_passwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,19 +504,21 @@ int main(int argc, char *argv[])
return 1;
}

if(username && strlen(username) > 65535){
fprintf(stderr, "Error: Username must be less than 65536 characters long.\n");
return 1;
if(username){
if(strlen(username) > 65535){
fprintf(stderr, "Error: Username must be less than 65536 characters long.\n");
return 1;
}
if(strchr(username, ':')){
fprintf(stderr, "Error: Username must not contain the ':' character.\n");
return 1;
}
}
if(password_cmd && strlen(password_cmd) > 65535){
fprintf(stderr, "Error: Password must be less than 65536 characters long.\n");
return 1;
}

if(strchr(username, ':')){
fprintf(stderr, "Error: Username must not contain the ':' character.\n");
return 1;
}
#ifdef WIN32
password_file = _fullpath(NULL, password_file_tmp, 0);
if(!password_file){
Expand Down
4 changes: 3 additions & 1 deletion plugins/dynamic-security/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ void dynsec__config_save(void)
fclose(fptr);

/* Everything is ok, so move new file over proper file */
rename(file_path, config_file);
if(rename(file_path, config_file) < 0){
mosquitto_log_printf(MOSQ_LOG_ERR, "Error updating dynsec config file: %s", strerror(errno));
}
mosquitto_free(file_path);
}

Expand Down
2 changes: 1 addition & 1 deletion src/mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ int main(int argc, char *argv[])
mosquitto_security_module_cleanup();

if(config.pid_file){
remove(config.pid_file);
(void)remove(config.pid_file);
}

log__close(&config);
Expand Down
3 changes: 2 additions & 1 deletion src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,8 @@ static int net__socket_listen_tcp(struct mosquitto__listener *listener)

#ifndef WIN32
ss_opt = 1;
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &ss_opt, sizeof(ss_opt));
/* Unimportant if this fails */
(void)setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &ss_opt, sizeof(ss_opt));
#endif
#ifdef IPV6_V6ONLY
ss_opt = 1;
Expand Down

0 comments on commit 0c63657

Please sign in to comment.