Coverity Scan issues.

1436823
1436837
1436843
1432792
1436847
1436848
1436849
This commit is contained in:
Roger A. Light 2020-11-24 00:58:01 +00:00
parent f83fcc8535
commit 0c6365726f
5 changed files with 29 additions and 15 deletions

View File

@ -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)); 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->source_mid = chunk.F.source_mid;
stored->topic = chunk.topic; stored->topic = chunk.topic;
stored->qos = chunk.F.qos; stored->qos = chunk.F.qos;
@ -286,12 +295,9 @@ static int dump__msg_store_chunk_process(FILE *db_fptr, uint32_t length)
chunk.source.username = NULL; chunk.source.username = NULL;
if(rc == MOSQ_ERR_SUCCESS){ if(rc == MOSQ_ERR_SUCCESS){
/*
printf("stored:%p\n", stored);
stored->source_listener = chunk.source.listener; stored->source_listener = chunk.source.listener;
load->db_id = stored->db_id; load->db_id = stored->db_id;
load->store = stored; load->store = stored;
*/
HASH_ADD(hh, db.msg_store_load, db_id, sizeof(dbid_t), load); HASH_ADD(hh, db.msg_store_load, db_id, sizeof(dbid_t), load);
}else{ }else{
@ -455,7 +461,10 @@ int main(int argc, char *argv[])
default: default:
fprintf(stderr, "Warning: Unsupported chunk \"%d\" in persistent database file. Ignoring.\n", chunk); 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; break;
} }
} }
@ -486,7 +495,7 @@ int main(int argc, char *argv[])
return rc; return rc;
error: error:
fprintf(stderr, "Error: %s.", strerror(errno)); fprintf(stderr, "Error: %s.", strerror(errno));
if(fd >= 0) fclose(fd); if(fd) fclose(fd);
return 1; return 1;
} }

View File

@ -504,19 +504,21 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
if(username && strlen(username) > 65535){ if(username){
if(strlen(username) > 65535){
fprintf(stderr, "Error: Username must be less than 65536 characters long.\n"); fprintf(stderr, "Error: Username must be less than 65536 characters long.\n");
return 1; return 1;
} }
if(strchr(username, ':')){
fprintf(stderr, "Error: Username must not contain the ':' character.\n");
return 1;
}
}
if(password_cmd && strlen(password_cmd) > 65535){ if(password_cmd && strlen(password_cmd) > 65535){
fprintf(stderr, "Error: Password must be less than 65536 characters long.\n"); fprintf(stderr, "Error: Password must be less than 65536 characters long.\n");
return 1; return 1;
} }
if(strchr(username, ':')){
fprintf(stderr, "Error: Username must not contain the ':' character.\n");
return 1;
}
#ifdef WIN32 #ifdef WIN32
password_file = _fullpath(NULL, password_file_tmp, 0); password_file = _fullpath(NULL, password_file_tmp, 0);
if(!password_file){ if(!password_file){

View File

@ -471,7 +471,9 @@ void dynsec__config_save(void)
fclose(fptr); fclose(fptr);
/* Everything is ok, so move new file over proper file */ /* 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); mosquitto_free(file_path);
} }

View File

@ -568,7 +568,7 @@ int main(int argc, char *argv[])
mosquitto_security_module_cleanup(); mosquitto_security_module_cleanup();
if(config.pid_file){ if(config.pid_file){
remove(config.pid_file); (void)remove(config.pid_file);
} }
log__close(&config); log__close(&config);

View File

@ -645,7 +645,8 @@ static int net__socket_listen_tcp(struct mosquitto__listener *listener)
#ifndef WIN32 #ifndef WIN32
ss_opt = 1; 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 #endif
#ifdef IPV6_V6ONLY #ifdef IPV6_V6ONLY
ss_opt = 1; ss_opt = 1;