Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Jul 18, 2017
2 parents ba0122f + 46630e7 commit 5a26736
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 17 deletions.
7 changes: 7 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ Build:
build and install static versions of the client libraries.


1.4.14 - 20170710
=================

Broker:
- Fix regression from 1.4.13 where persistence data was not being saved.


1.4.13 - 20170627
=================

Expand Down
5 changes: 3 additions & 2 deletions lib/mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,9 +950,10 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
/* Fake write possible, to stimulate output write even though
* we didn't ask for it, because at that point the publish or
* other command wasn't present. */
FD_SET(mosq->sock, &writefds);
if(mosq->sock != INVALID_SOCKET)
FD_SET(mosq->sock, &writefds);
}
if(FD_ISSET(mosq->sock, &writefds)){
if(mosq->sock != INVALID_SOCKET && FD_ISSET(mosq->sock, &writefds)){
#ifdef WITH_TLS
if(mosq->want_connect){
rc = net__socket_connect_tls(mosq);
Expand Down
20 changes: 17 additions & 3 deletions lib/util_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,33 @@ int mosquitto__hex2bin(const char *hex, unsigned char *bin, int bin_max_len)
{
BIGNUM *bn = NULL;
int len;
int leading_zero = 0;
int start = 0;
int i = 0;

/* Count the number of leading zero */
for(i=0; i<strlen(hex); i=i+2) {
if(strncmp(hex + i, "00", 2) == 0) {
leading_zero++;
/* output leading zero to bin */
bin[start++] = 0;
}else{
break;
}
}

if(BN_hex2bn(&bn, hex) == 0){
if(bn) BN_free(bn);
return 0;
}
if(BN_num_bytes(bn) > bin_max_len){
if(BN_num_bytes(bn) + leading_zero > bin_max_len){
BN_free(bn);
return 0;
}

len = BN_bn2bin(bn, bin);
len = BN_bn2bin(bn, bin + leading_zero);
BN_free(bn);
return len;
return len + leading_zero;
}
#endif

Expand Down
6 changes: 3 additions & 3 deletions man/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ include ../config.mk
all : mosquitto.8 mosquitto-tls.7 mosquitto.conf.5 mosquitto_passwd.1 mosquitto_pub.1 mosquitto_sub.1 mqtt.7 libmosquitto.3

clean :

reallyclean : clean
-rm -f *.orig
-rm -f libmosquitto.3
-rm -f mosquitto.8
-rm -f mosquitto.conf.5
Expand All @@ -14,9 +17,6 @@ clean :
-rm -f mosquitto-tls.7
-rm -f mqtt.7

reallyclean : clean
-rm -f *.orig

dist : mosquitto.8 mosquitto-tls.7 mosquitto.conf.5 mosquitto_passwd.1 mosquitto_pub.1 mosquitto_sub.1 mqtt.7 libmosquitto.3

install :
Expand Down
2 changes: 1 addition & 1 deletion set-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

MAJOR=1
MINOR=4
REVISION=13
REVISION=14

sed -i "s/^VERSION=.*/VERSION=${MAJOR}.${MINOR}.${REVISION}/" config.mk

Expand Down
3 changes: 2 additions & 1 deletion src/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and the Eclipse Distribution License is available at
#include <assert.h>
#ifndef WIN32
#include <poll.h>
#include <unistd.h>
#else
#include <process.h>
#include <winsock2.h>
Expand Down Expand Up @@ -126,7 +127,7 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
#ifdef WIN32
pollfd_max = _getmaxstdio();
#else
pollfd_max = getdtablesize();
pollfd_max = sysconf(_SC_OPEN_MAX);
#endif

pollfds = mosquitto__malloc(sizeof(struct pollfd)*pollfd_max);
Expand Down
16 changes: 10 additions & 6 deletions src/mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ int main(int argc, char *argv[])
}
#endif

HASH_ITER(hh_id, int_db.contexts_by_id, ctxt, ctxt_tmp){
mqtt3_context_send_will(&int_db, ctxt);
}

#ifdef WITH_PERSISTENCE
if(config.persistence){
mqtt3_db_backup(&int_db, true);
}
#endif

HASH_ITER(hh_id, int_db.contexts_by_id, ctxt, ctxt_tmp){
#ifdef WITH_WEBSOCKETS
if(!ctxt->wsi){
Expand All @@ -396,12 +406,6 @@ int main(int argc, char *argv[])
#endif
context__free_disused(&int_db);

#ifdef WITH_PERSISTENCE
if(config.persistence){
persist__backup(&int_db, true);
}
#endif

db__close(&int_db);

if(listensock){
Expand Down
22 changes: 21 additions & 1 deletion src/security_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ static int pw__digest(const char *password, const unsigned char *salt, unsigned
static int base64__decode(char *in, unsigned char **decoded, unsigned int *decoded_len);
#endif

static int mosquitto__memcmp_const(const void *ptr1, const void *b, size_t len);


int mosquitto_security_init_default(struct mosquitto_db *db, bool reload)
{
int rc;
Expand Down Expand Up @@ -648,6 +651,23 @@ static int psk__file_parse(struct mosquitto_db *db)
return MOSQ_ERR_SUCCESS;
}


static int mosquitto__memcmp_const(const void *a, const void *b, size_t len)
{
int i;
int rc = 0;

if(!a || !b) return 1;

for(i=0; i<len; i++){
if( ((char *)a)[i] != ((char *)b)[i] ){
rc = 1;
}
}
return rc;
}


int mosquitto_unpwd_check_default(struct mosquitto_db *db, const char *username, const char *password)
{
struct mosquitto__unpwd *u, *tmp;
Expand All @@ -668,7 +688,7 @@ int mosquitto_unpwd_check_default(struct mosquitto_db *db, const char *username,
#ifdef WITH_TLS
rc = pw__digest(password, u->salt, u->salt_len, hash, &hash_len);
if(rc == MOSQ_ERR_SUCCESS){
if(hash_len == u->password_len && !memcmp(u->password, hash, hash_len)){
if(hash_len == u->password_len && !mosquitto__memcmp_const(u->password, hash, hash_len)){
return MOSQ_ERR_SUCCESS;
}else{
return MOSQ_ERR_AUTH;
Expand Down

0 comments on commit 5a26736

Please sign in to comment.