Coverity fixes

1399064
1399065
1398655
1398656
1398654
1399067
1399066
1399063
1399060
1399059
1399068
1399062
1398657
1398653
1302848
1302847
1399070
pull/1203/head
Roger A. Light 7 years ago
parent e334aad853
commit 72941db546

2
.gitignore vendored

@ -18,6 +18,8 @@ build/
client/mosquitto_pub client/mosquitto_pub
client/mosquitto_sub client/mosquitto_sub
cov-int/
dist/ dist/
examples/mysql_log/mosquitto_mysql_log examples/mysql_log/mosquitto_mysql_log

@ -36,11 +36,14 @@ reallyclean :
$(MAKE) -C test reallyclean $(MAKE) -C test reallyclean
-rm -f *.orig -rm -f *.orig
test : mosquitto
$(MAKE) -C test test
ptest : mosquitto ptest : mosquitto
$(MAKE) -C test ptest $(MAKE) -C test ptest
test : mosquitto utest : mosquitto
$(MAKE) -C test test $(MAKE) -C test utest
install : mosquitto install : mosquitto
set -e; for d in ${DIRS}; do $(MAKE) -C $${d} install; done set -e; for d in ${DIRS}; do $(MAKE) -C $${d} install; done

@ -47,4 +47,15 @@
# endif # endif
#endif #endif
#ifdef __COVERITY__
# include <stdint.h>
/* These are "wrong", but we don't use them so it doesn't matter */
# define _Float32 uint32_t
# define _Float32x uint32_t
# define _Float64 uint64_t
# define _Float64x uint64_t
# define _Float128 uint64_t
#endif
#endif #endif

@ -70,7 +70,6 @@ int handle__pubackcomp(struct mosquitto *mosq, const char *type)
/* Immediately free, we don't do anything with Reason String or User Property at the moment */ /* Immediately free, we don't do anything with Reason String or User Property at the moment */
mosquitto_property_free_all(&properties); mosquitto_property_free_all(&properties);
if(mid){
rc = db__message_delete(db, mosq, mid, mosq_md_out, mosq_ms_wait_for_pubcomp, qos); rc = db__message_delete(db, mosq, mid, mosq_md_out, mosq_ms_wait_for_pubcomp, qos);
if(rc == MOSQ_ERR_NOT_FOUND){ if(rc == MOSQ_ERR_NOT_FOUND){
log__printf(mosq, MOSQ_LOG_WARNING, "Warning: Received %s from %s for an unknown packet identifier %d.", type, mosq->id, mid); log__printf(mosq, MOSQ_LOG_WARNING, "Warning: Received %s from %s for an unknown packet identifier %d.", type, mosq->id, mid);
@ -78,7 +77,6 @@ int handle__pubackcomp(struct mosquitto *mosq, const char *type)
}else{ }else{
return rc; return rc;
} }
}
#else #else
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received %s (Mid: %d)", mosq->id, type, mid); log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received %s (Mid: %d)", mosq->id, type, mid);
@ -101,8 +99,8 @@ int handle__pubackcomp(struct mosquitto *mosq, const char *type)
pthread_mutex_unlock(&mosq->callback_mutex); pthread_mutex_unlock(&mosq->callback_mutex);
mosquitto_property_free_all(&properties); mosquitto_property_free_all(&properties);
} }
#endif
return MOSQ_ERR_SUCCESS; return MOSQ_ERR_SUCCESS;
#endif
} }

@ -230,6 +230,7 @@ int message__remove(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_dir
while(cur){ while(cur){
if(cur->msg.mid == mid){ if(cur->msg.mid == mid){
if(cur->msg.qos != qos){ if(cur->msg.qos != qos){
pthread_mutex_unlock(&mosq->out_message_mutex);
return MOSQ_ERR_PROTOCOL; return MOSQ_ERR_PROTOCOL;
} }
if(prev){ if(prev){
@ -287,6 +288,7 @@ int message__remove(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_dir
while(cur){ while(cur){
if(cur->msg.mid == mid){ if(cur->msg.mid == mid){
if(cur->msg.qos != qos){ if(cur->msg.qos != qos){
pthread_mutex_unlock(&mosq->in_message_mutex);
return MOSQ_ERR_PROTOCOL; return MOSQ_ERR_PROTOCOL;
} }
if(prev){ if(prev){
@ -382,6 +384,7 @@ int message__out_update(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg
while(message){ while(message){
if(message->msg.mid == mid){ if(message->msg.mid == mid){
if(message->msg.qos != qos){ if(message->msg.qos != qos){
pthread_mutex_unlock(&mosq->out_message_mutex);
return MOSQ_ERR_PROTOCOL; return MOSQ_ERR_PROTOCOL;
} }
message->state = state; message->state = state;

@ -39,6 +39,8 @@ int property__read(struct mosquitto__packet *packet, int32_t *len, mosquitto_pro
char *str1, *str2; char *str1, *str2;
int slen1, slen2; int slen1, slen2;
if(!property) return MOSQ_ERR_INVAL;
rc = packet__read_varint(packet, &property_identifier, NULL); rc = packet__read_varint(packet, &property_identifier, NULL);
if(rc) return rc; if(rc) return rc;
*len -= 1; *len -= 1;
@ -131,7 +133,7 @@ int property__read(struct mosquitto__packet *packet, int32_t *len, mosquitto_pro
break; break;
default: default:
log__printf(NULL, MOSQ_LOG_DEBUG, "Unsupported property type: %d", byte); log__printf(NULL, MOSQ_LOG_DEBUG, "Unsupported property type: %d", property_identifier);
return MOSQ_ERR_MALFORMED_PACKET; return MOSQ_ERR_MALFORMED_PACKET;
} }
@ -154,6 +156,10 @@ int property__read_all(int command, struct mosquitto__packet *packet, mosquitto_
* same order for all */ * same order for all */
while(proplen > 0){ while(proplen > 0){
p = mosquitto__calloc(1, sizeof(mosquitto_property)); p = mosquitto__calloc(1, sizeof(mosquitto_property));
if(!p){
mosquitto_property_free_all(properties);
return MOSQ_ERR_NOMEM;
}
rc = property__read(packet, &proplen, p); rc = property__read(packet, &proplen, p);
if(rc){ if(rc){
@ -1002,7 +1008,7 @@ const mosquitto_property *mosquitto_property_read_binary(const mosquitto_propert
if(value){ if(value){
*len = p->value.bin.len; *len = p->value.bin.len;
*value = malloc(*len); *value = malloc(*len);
if(!value) return NULL; if(!(*value)) return NULL;
memcpy(*value, p->value.bin.v, *len); memcpy(*value, p->value.bin.v, *len);
} }
@ -1031,12 +1037,11 @@ const mosquitto_property *mosquitto_property_read_string(const mosquitto_propert
if(value){ if(value){
*value = calloc(1, p->value.s.len+1); *value = calloc(1, p->value.s.len+1);
if(!value) return NULL; if(!(*value)) return NULL;
memcpy(*value, p->value.s.v, p->value.s.len); memcpy(*value, p->value.s.v, p->value.s.len);
} }
return p; return p;
} }
@ -1052,13 +1057,13 @@ const mosquitto_property *mosquitto_property_read_string_pair(const mosquitto_pr
if(name){ if(name){
*name = calloc(1, p->name.len+1); *name = calloc(1, p->name.len+1);
if(!name) return NULL; if(!(*name)) return NULL;
memcpy(*name, p->name.v, p->name.len); memcpy(*name, p->name.v, p->name.len);
} }
if(value){ if(value){
*value = calloc(1, p->value.s.len+1); *value = calloc(1, p->value.s.len+1);
if(!value){ if(!(*value)){
if(name) free(*name); if(name) free(*name);
return NULL; return NULL;
} }

@ -68,9 +68,9 @@ int send__pingresp(struct mosquitto *mosq)
int send__puback(struct mosquitto *mosq, uint16_t mid) int send__puback(struct mosquitto *mosq, uint16_t mid)
{ {
#ifdef WITH_BROKER #ifdef WITH_BROKER
if(mosq) log__printf(NULL, MOSQ_LOG_DEBUG, "Sending PUBACK to %s (Mid: %d)", mosq->id, mid); log__printf(NULL, MOSQ_LOG_DEBUG, "Sending PUBACK to %s (Mid: %d)", mosq->id, mid);
#else #else
if(mosq) log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending PUBACK (Mid: %d)", mosq->id, mid); log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending PUBACK (Mid: %d)", mosq->id, mid);
#endif #endif
util__increment_receive_quota(mosq); util__increment_receive_quota(mosq);
/* We don't use Reason String or User Property yet. */ /* We don't use Reason String or User Property yet. */
@ -80,9 +80,9 @@ int send__puback(struct mosquitto *mosq, uint16_t mid)
int send__pubcomp(struct mosquitto *mosq, uint16_t mid) int send__pubcomp(struct mosquitto *mosq, uint16_t mid)
{ {
#ifdef WITH_BROKER #ifdef WITH_BROKER
if(mosq) log__printf(NULL, MOSQ_LOG_DEBUG, "Sending PUBCOMP to %s (Mid: %d)", mosq->id, mid); log__printf(NULL, MOSQ_LOG_DEBUG, "Sending PUBCOMP to %s (Mid: %d)", mosq->id, mid);
#else #else
if(mosq) log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending PUBCOMP (Mid: %d)", mosq->id, mid); log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending PUBCOMP (Mid: %d)", mosq->id, mid);
#endif #endif
util__increment_receive_quota(mosq); util__increment_receive_quota(mosq);
/* We don't use Reason String or User Property yet. */ /* We don't use Reason String or User Property yet. */

@ -102,7 +102,9 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun
FindClose(fh); FindClose(fh);
if(l_files){
qsort(l_files, l_file_count, sizeof(char *), scmp_p); qsort(l_files, l_file_count, sizeof(char *), scmp_p);
}
*files = l_files; *files = l_files;
*file_count = l_file_count; *file_count = l_file_count;
@ -166,7 +168,9 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun
} }
closedir(dh); closedir(dh);
if(l_files){
qsort(l_files, l_file_count, sizeof(char *), scmp_p); qsort(l_files, l_file_count, sizeof(char *), scmp_p);
}
*files = l_files; *files = l_files;
*file_count = l_file_count; *file_count = l_file_count;

@ -152,7 +152,7 @@ void context__cleanup(struct mosquitto_db *db, struct mosquitto *context, bool d
context->password = NULL; context->password = NULL;
net__socket_close(db, context); net__socket_close(db, context);
if((do_free || context->clean_start) && db){ if(do_free || context->clean_start){
sub__clean_session(db, context); sub__clean_session(db, context);
db__messages_delete(db, context); db__messages_delete(db, context);
} }
@ -163,9 +163,6 @@ void context__cleanup(struct mosquitto_db *db, struct mosquitto *context, bool d
context__send_will(db, context); context__send_will(db, context);
if(context->id){ if(context->id){
assert(db); /* db can only be NULL here if the client hasn't sent a
CONNECT and hence wouldn't have an id. */
context__remove_from_by_id(db, context); context__remove_from_by_id(db, context);
mosquitto__free(context->id); mosquitto__free(context->id);
context->id = NULL; context->id = NULL;

@ -703,6 +703,7 @@ error:
mosquitto__free(temp); mosquitto__free(temp);
} }
mosquitto_property_free_all(&properties); mosquitto_property_free_all(&properties);
UHPA_FREE(*payload, payloadlen);
return rc; return rc;
} }

@ -170,7 +170,7 @@ static int persist__message_store_write(struct mosquitto_db *db, FILE *db_fptr)
}else{ }else{
tlen = 0; tlen = 0;
} }
length = sizeof(dbid_t) + 2+strlen(stored->source_id) + length = sizeof(dbid_t) + sizeof(uint16_t) +
sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint16_t) +
2+tlen + sizeof(uint32_t) + 2+tlen + sizeof(uint32_t) +
stored->payloadlen + sizeof(uint8_t) + sizeof(uint8_t) stored->payloadlen + sizeof(uint8_t) + sizeof(uint8_t)
@ -770,7 +770,6 @@ static int persist__msg_store_chunk_restore(struct mosquitto_db *db, FILE *db_fp
mosquitto__free(load); mosquitto__free(load);
fclose(db_fptr); fclose(db_fptr);
mosquitto__free(source.id); mosquitto__free(source.id);
mosquitto__free(source.id);
return rc; return rc;
} }
@ -808,8 +807,6 @@ static int persist__msg_store_chunk_restore(struct mosquitto_db *db, FILE *db_fp
}else{ }else{
mosquitto__free(load); mosquitto__free(load);
fclose(db_fptr); fclose(db_fptr);
mosquitto__free(topic);
UHPA_FREE(payload, payloadlen);
return rc; return rc;
} }
error: error:
@ -818,8 +815,6 @@ error:
fclose(db_fptr); fclose(db_fptr);
mosquitto__free(source.id); mosquitto__free(source.id);
mosquitto__free(source.username); mosquitto__free(source.username);
mosquitto__free(topic);
UHPA_FREE(payload, payloadlen);
return 1; return 1;
} }

@ -36,13 +36,11 @@ int send__connack(struct mosquitto_db *db, struct mosquitto *context, int ack, i
return rc; return rc;
} }
if(context){
if(context->id){ if(context->id){
log__printf(NULL, MOSQ_LOG_DEBUG, "Sending CONNACK to %s (%d, %d)", context->id, ack, reason_code); log__printf(NULL, MOSQ_LOG_DEBUG, "Sending CONNACK to %s (%d, %d)", context->id, ack, reason_code);
}else{ }else{
log__printf(NULL, MOSQ_LOG_DEBUG, "Sending CONNACK to %s (%d, %d)", context->address, ack, reason_code); log__printf(NULL, MOSQ_LOG_DEBUG, "Sending CONNACK to %s (%d, %d)", context->address, ack, reason_code);
} }
}
remaining_length = 2; remaining_length = 2;

@ -4,14 +4,15 @@ include ../config.mk
all : all :
test : test : utest
$(MAKE) -C broker test $(MAKE) -C broker test
$(MAKE) -C lib test $(MAKE) -C lib test
$(MAKE) -C unit test
ptest : ptest : utest
$(MAKE) -C broker ptest $(MAKE) -C broker ptest
$(MAKE) -C lib ptest $(MAKE) -C lib ptest
utest :
$(MAKE) -C unit test $(MAKE) -C unit test
clean : clean :

@ -1,3 +1,4 @@
#include "config.h"
#include <stdio.h> #include <stdio.h>
#include <CUnit/CUnit.h> #include <CUnit/CUnit.h>

Loading…
Cancel
Save