Skip to content

Commit

Permalink
fix(uv_ssl_t): fixed memory issues concerning ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
martinopresnik authored and jkuri committed May 18, 2018
1 parent d63a733 commit e369673
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bproxy.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"gypkg_deps": [
"git://github.com/libuv/libuv.git@^v1.x => uv.gyp:libuv",
"git://github.com/indutny/[email protected] => uv_link_t.gyp:uv_link_t",
"git://github.com/indutny/uv_ssl_t@v1.0.5 => uv_ssl_t.gyp:uv_ssl_t",
"git://github.com/martinopresnik/uv_ssl_t@1.0.10 => uv_ssl_t.gyp:uv_ssl_t",
"git://github.com/gypkg/openssl@~1.2.7 => openssl.gyp:openssl",
"3rdparty/zlib => gyp/zlib.gyp:zlib"
]
Expand Down
1 change: 1 addition & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "log.h"

#include "openssl/ssl.h"
#include "uv_ssl_t.h"

#define CONFIG_MAX_HOSTS 10
#define CONFIG_MAX_GZIP_MIME_TYPES 20
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"test": "node ./test/run.js",
"build": "gypkg build bproxy.gyp",
"build": "gypkg build bproxy.gyp --insecure",
"clean": "rimraf gypkg_deps out",
"log": "conventional-changelog -p angular -i CHANGELOG.md -s"
},
Expand Down
5 changes: 5 additions & 0 deletions src/bproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ static int ssl_servername_cb(SSL *s, int *ad, void *arg)
{
conn_t *conn = (conn_t *)arg;
const char *hostname = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
if (!hostname)
{
hostname = "";
}
proxy_config_t *proxy_config = find_proxy_config(hostname);
if (!proxy_config)
{
Expand Down Expand Up @@ -412,6 +416,7 @@ void parse_args(int argc, char **argv)
{
char *json = read_file(server->config_file);
parse_config(json, server->config);
free(json);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void parse_config(const char *json_string, config_t *config)
config->num_proxies++;

config->proxies[config->num_proxies - 1] = malloc(sizeof(proxy_config_t));
memset(config->proxies[config->num_proxies - 1], 0, sizeof(proxy_config_t));
proxy_hosts = cJSON_GetObjectItemCaseSensitive(proxy, "hosts");
config->proxies[config->num_proxies - 1]->num_hosts = 0;
cJSON_ArrayForEach(proxy_host, proxy_hosts)
Expand Down Expand Up @@ -173,6 +174,14 @@ void parse_config(const char *json_string, config_t *config)
ssl_enabled = false;
}
}
if (ssl_enabled)
{
if (uv_ssl_setup_recommended_secure_context(config->proxies[config->num_proxies - 1]->ssl_context))
{
log_error("configuring recommended secure context");
ssl_enabled = false;
}
}
if (!ssl_enabled)
{
SSL_CTX_free(config->proxies[config->num_proxies - 1]->ssl_context);
Expand Down

0 comments on commit e369673

Please sign in to comment.