Skip to content

Commit

Permalink
Fixes for the poor souls stuck on <c99.
Browse files Browse the repository at this point in the history
Closes #1622.
  • Loading branch information
ralight committed Mar 12, 2020
1 parent c175e83 commit c84d175
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 119 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.txt
@@ -1,3 +1,7 @@
Build:
- Various fixes for building with <C99 support. Closes #1622.


1.6.9 - 20200227
================

Expand Down
16 changes: 9 additions & 7 deletions lib/memory_mosq.c
Expand Up @@ -47,12 +47,13 @@ void memory__set_limit(size_t lim)

void *mosquitto__calloc(size_t nmemb, size_t size)
{
void *mem;
#ifdef REAL_WITH_MEMORY_TRACKING
if(mem_limit && memcount + size > mem_limit){
return NULL;
}
#endif
void *mem = calloc(nmemb, size);
mem = calloc(nmemb, size);

#ifdef REAL_WITH_MEMORY_TRACKING
if(mem){
Expand All @@ -79,12 +80,15 @@ void mosquitto__free(void *mem)

void *mosquitto__malloc(size_t size)
{
void *mem;

#ifdef REAL_WITH_MEMORY_TRACKING
if(mem_limit && memcount + size > mem_limit){
return NULL;
}
#endif
void *mem = malloc(size);

mem = malloc(size);

#ifdef REAL_WITH_MEMORY_TRACKING
if(mem){
Expand Down Expand Up @@ -112,13 +116,11 @@ unsigned long mosquitto__max_memory_used(void)

void *mosquitto__realloc(void *ptr, size_t size)
{
void *mem;
#ifdef REAL_WITH_MEMORY_TRACKING
if(mem_limit && memcount + size > mem_limit){
return NULL;
}
#endif
void *mem;
#ifdef REAL_WITH_MEMORY_TRACKING
if(ptr){
memcount -= malloc_usable_size(ptr);
}
Expand All @@ -139,12 +141,13 @@ void *mosquitto__realloc(void *ptr, size_t size)

char *mosquitto__strdup(const char *s)
{
char *str;
#ifdef REAL_WITH_MEMORY_TRACKING
if(mem_limit && memcount + strlen(s) > mem_limit){
return NULL;
}
#endif
char *str = strdup(s);
str = strdup(s);

#ifdef REAL_WITH_MEMORY_TRACKING
if(str){
Expand All @@ -157,4 +160,3 @@ char *mosquitto__strdup(const char *s)

return str;
}

3 changes: 1 addition & 2 deletions lib/mosquitto_internal.h
Expand Up @@ -165,7 +165,6 @@ struct mosquitto_message_all{
struct mosquitto_message_all *prev;
mosquitto_property *properties;
time_t timestamp;
//enum mosquitto_msg_direction direction;
enum mosquitto_msg_state state;
bool dup;
struct mosquitto_message msg;
Expand Down Expand Up @@ -321,7 +320,7 @@ struct mosquitto {
void (*on_unsubscribe)(struct mosquitto *, void *userdata, int mid);
void (*on_unsubscribe_v5)(struct mosquitto *, void *userdata, int mid, const mosquitto_property *props);
void (*on_log)(struct mosquitto *, void *userdata, int level, const char *str);
//void (*on_error)();
/*void (*on_error)();*/
char *host;
int port;
char *bind_address;
Expand Down
11 changes: 7 additions & 4 deletions lib/net_mosq.c
Expand Up @@ -482,11 +482,11 @@ void net__print_ssl_error(struct mosquitto *mosq)
int net__socket_connect_tls(struct mosquitto *mosq)
{
int ret, err;
long res;

ERR_clear_error();
long res;
if (mosq->tls_ocsp_required) {
// Note: OCSP is available in all currently supported OpenSSL versions.
/* Note: OCSP is available in all currently supported OpenSSL versions. */
if ((res=SSL_set_tlsext_status_type(mosq->ssl, TLSEXT_STATUSTYPE_ocsp)) != 1) {
log__printf(mosq, MOSQ_LOG_ERR, "Could not activate OCSP (error: %ld)", res);
return MOSQ_ERR_OCSP;
Expand Down Expand Up @@ -537,6 +537,9 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
ENGINE *engine = NULL;
uint8_t tls_alpn_wire[256];
uint8_t tls_alpn_len;
#if !defined(OPENSSL_NO_ENGINE)
EVP_PKEY *pkey;
#endif

if(mosq->ssl_ctx){
if(!mosq->ssl_ctx_defaults){
Expand Down Expand Up @@ -595,7 +598,7 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
/* Set ALPN */
if(mosq->tls_alpn) {
tls_alpn_len = (uint8_t) strnlen(mosq->tls_alpn, 254);
tls_alpn_wire[0] = tls_alpn_len; // first byte is length of string
tls_alpn_wire[0] = tls_alpn_len; /* first byte is length of string */
memcpy(tls_alpn_wire + 1, mosq->tls_alpn, tls_alpn_len);
SSL_CTX_set_alpn_protos(mosq->ssl_ctx, tls_alpn_wire, tls_alpn_len + 1);
}
Expand Down Expand Up @@ -718,7 +721,7 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
}
ui_method = NULL;
}
EVP_PKEY *pkey = ENGINE_load_private_key(engine, mosq->tls_keyfile, ui_method, NULL);
pkey = ENGINE_load_private_key(engine, mosq->tls_keyfile, ui_method, NULL);
if(!pkey){
log__printf(mosq, MOSQ_LOG_ERR, "Error: Unable to load engine private key file \"%s\".", mosq->tls_keyfile);
ENGINE_FINISH(engine);
Expand Down
15 changes: 8 additions & 7 deletions lib/net_mosq_ocsp.c
Expand Up @@ -64,7 +64,7 @@ int mosquitto__verify_ocsp_status_cb(SSL * ssl, void *arg)
long len = SSL_get_tlsext_status_ocsp_resp(mosq->ssl, &p);
log__printf(mosq, MOSQ_LOG_DEBUG, "OCSP: SSL_get_tlsext_status_ocsp_resp returned %ld bytes", len);

// the following functions expect a const pointer
/* the following functions expect a const pointer */
cp = (const unsigned char *)p;

if (!cp || len <= 0) {
Expand Down Expand Up @@ -100,9 +100,10 @@ int mosquitto__verify_ocsp_status_cb(SSL * ssl, void *arg)

st = SSL_CTX_get_cert_store(mosq->ssl_ctx);

// Note:
// Other checkers often fix problems in OpenSSL before 1.0.2a (e.g. libcurl).
// For all currently supported versions of the OpenSSL project, this is not needed anymore.
/* Note:
* Other checkers often fix problems in OpenSSL before 1.0.2a (e.g. libcurl).
* For all currently supported versions of the OpenSSL project, this is not needed anymore.
*/

if ((result2=OCSP_basic_verify(br, ch, st, 0)) <= 0) {
log__printf(mosq, MOSQ_LOG_DEBUG, "OCSP: response verification failed (error: %d)", result2);
Expand All @@ -126,7 +127,7 @@ int mosquitto__verify_ocsp_status_cb(SSL * ssl, void *arg)

switch(cert_status) {
case V_OCSP_CERTSTATUS_GOOD:
// Note: A OCSP stapling result will be accepted up to 5 minutes after it expired!
/* Note: A OCSP stapling result will be accepted up to 5 minutes after it expired! */
if(!OCSP_check_validity(thisupd, nextupd, 300L, -1L)) {
log__printf(mosq, MOSQ_LOG_DEBUG, "OCSP: OCSP response has expired");
goto end;
Expand All @@ -149,11 +150,11 @@ int mosquitto__verify_ocsp_status_cb(SSL * ssl, void *arg)

if (br!=NULL) OCSP_BASICRESP_free(br);
if (rsp!=NULL) OCSP_RESPONSE_free(rsp);
return 1; // OK
return 1; /* OK */

end:
if (br!=NULL) OCSP_BASICRESP_free(br);
if (rsp!=NULL) OCSP_RESPONSE_free(rsp);
return 0; // Not OK
return 0; /* Not OK */
}
#endif
4 changes: 2 additions & 2 deletions lib/utf8_mosq.c
Expand Up @@ -45,11 +45,11 @@ int mosquitto_validate_utf8(const char *str, int len)
codelen = 2;
codepoint = (ustr[i] & 0x1F);
}else if((ustr[i] & 0xF0) == 0xE0){
// 1110xxxx - 3 byte sequence
/* 1110xxxx - 3 byte sequence */
codelen = 3;
codepoint = (ustr[i] & 0x0F);
}else if((ustr[i] & 0xF8) == 0xF0){
// 11110xxx - 4 byte sequence
/* 11110xxx - 4 byte sequence */
if(ustr[i] > 0xF4){
/* Invalid, this would produce values > 0x10FFFF. */
return MOSQ_ERR_MALFORMED_UTF8;
Expand Down

0 comments on commit c84d175

Please sign in to comment.