Skip to content

Commit

Permalink
Fix Coverity Scan issues.
Browse files Browse the repository at this point in the history
1436866
1436865
1436864
1436862
1436857
1436856
1436852
1436851
  • Loading branch information
ralight committed Nov 24, 2020
1 parent d142ff6 commit f83fcc8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
1 change: 0 additions & 1 deletion apps/db_dump/db_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ static int dump__client_chunk_process(FILE *db_fd, uint32_t length)
}
if(rc){
fprintf(stderr, "Error: Corrupt persistent database.");
fclose(db_fd);
return rc;
}

Expand Down
7 changes: 6 additions & 1 deletion apps/mosquitto_ctrl/dynsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,11 @@ static cJSON *init_add_client(const char *username, const char *password, const
}

j_client = cJSON_CreateObject();
if(j_client == NULL) return NULL;
if(j_client == NULL){
free(salt64);
free(hash64);
return NULL;
}

snprintf(buf, sizeof(buf), "%d", PW_DEFAULT_ITERATIONS);
if(cJSON_AddStringToObject(j_client, "username", username) == NULL
Expand Down Expand Up @@ -739,6 +743,7 @@ int dynsec_init(int argc, char *argv[])
if(fptr){
fprintf(fptr, "%s", json_str);
free(json_str);
fclose(fptr);
}else{
free(json_str);
fprintf(stderr, "dynsec init: Unable to open '%s' for writing.\n", filename);
Expand Down
1 change: 1 addition & 0 deletions apps/mosquitto_ctrl/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ int client_config_load(struct mosq_config *cfg)
local_args = malloc(3*sizeof(char *));
if(local_args == NULL){
fprintf(stderr, "Error: Out of memory.\n");
fclose(fptr);
return 1;
}
while(fgets(line, 1024, fptr)){
Expand Down
14 changes: 13 additions & 1 deletion plugins/dynamic-security/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and the Eclipse Distribution License is available at
#include "config.h"

#include <cJSON.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -343,6 +344,7 @@ static int dynsec__general_config_save(cJSON *tree)
static int dynsec__config_load(void)
{
FILE *fptr;
long flen_l;
size_t flen;
char *json_str;
cJSON *tree;
Expand All @@ -354,14 +356,24 @@ static int dynsec__config_load(void)
}

fseek(fptr, 0, SEEK_END);
flen = (size_t)ftell(fptr);
flen_l = ftell(fptr);
if(flen_l < 0){
mosquitto_log_printf(MOSQ_LOG_WARNING, "Error loading Dynamic security plugin config: %s\n", strerror(errno));
fclose(fptr);
return 1;
}else if(flen_l == 0){
fclose(fptr);
return 0;
}
flen = (size_t)flen_l;
fseek(fptr, 0, SEEK_SET);
json_str = mosquitto_calloc(flen+1, sizeof(char));
if(json_str == NULL){
fclose(fptr);
return 1;
}
if(fread(json_str, 1, flen, fptr) != flen){
mosquitto_free(json_str);
fclose(fptr);
return 1;
}
Expand Down
7 changes: 4 additions & 3 deletions plugins/dynamic-security/roles.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ int dynsec_roles__process_add_acl(cJSON *j_responses, struct mosquitto *context,

acl = mosquitto_calloc(1, sizeof(struct dynsec__acl));
if(acl == NULL){
mosquitto_free(topic);
dynsec__command_reply(j_responses, context, "addRoleACL", "Internal error", correlation_data);
return MOSQ_ERR_SUCCESS;
}
Expand Down Expand Up @@ -833,9 +834,9 @@ int dynsec_roles__process_modify(cJSON *j_responses, struct mosquitto *context,
struct dynsec__role *role;
char *str;
cJSON *j_acls;
struct dynsec__acl *tmp_publish_c_send, *tmp_publish_c_recv;
struct dynsec__acl *tmp_subscribe_literal, *tmp_subscribe_pattern;
struct dynsec__acl *tmp_unsubscribe_literal, *tmp_unsubscribe_pattern;
struct dynsec__acl *tmp_publish_c_send = NULL, *tmp_publish_c_recv = NULL;
struct dynsec__acl *tmp_subscribe_literal = NULL, *tmp_subscribe_pattern = NULL;
struct dynsec__acl *tmp_unsubscribe_literal = NULL, *tmp_unsubscribe_pattern = NULL;

if(json_get_string(command, "rolename", &rolename, false) != MOSQ_ERR_SUCCESS){
dynsec__command_reply(j_responses, context, "modifyRole", "Invalid/missing rolename", correlation_data);
Expand Down

0 comments on commit f83fcc8

Please sign in to comment.