Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ssl_options and misaligned adressinfo #52

Merged
merged 1 commit into from
Sep 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ do { \
do_hook(H_DISCONNECT, "%% Connection to %s closed: %s: %s", "%s %s: %s", \
where, what, why)

#define ROUND_UP_LENGTH(len) ((len + 7) & -8)

#if HAVE_SSL
static void ssl_err(const char *str)
{
Expand Down Expand Up @@ -604,8 +606,8 @@ typedef struct {
int verify_depth;
int always_continue;
} ssl_options_t;
ssl_options_t ssl_options;
int ssl_mydata_index;
static ssl_options_t ssl_options;
static int ssl_mydata_index;

static int ssl_verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
{
Expand Down Expand Up @@ -1409,7 +1411,6 @@ static int opensock(World *world, int flags)
SSL_CTX_set_verify_depth(ssl_ctx, ssl_depth);
ssl_mydata_index = SSL_get_ex_new_index(0, "ssl_mydata index",
NULL, NULL, NULL);
ssl_options_t ssl_options;
ssl_options.verify_depth = ssl_depth;
ssl_options.verbose_mode = ssl_verbose;
ssl_options.always_continue = ssl_continue;
Expand Down Expand Up @@ -1628,8 +1629,8 @@ static int openconn(Sock *sock)
for (ai = xsock->addrs; ai; ai = ai->ai_next) {
ai->ai_addr = (struct sockaddr*)((char*)ai + sizeof(*ai));
if (ai->ai_next != 0) {
ai->ai_next =
(struct addrinfo*)((char*)ai->ai_addr + ai->ai_addrlen);
ai->ai_next =
(struct addrinfo*)((char*)ai->ai_addr + ROUND_UP_LENGTH(ai->ai_addrlen));
}
}
xsock->addr = xsock->addrs;
Expand Down Expand Up @@ -1933,13 +1934,21 @@ static void waitforhostname(int fd, const char *name, const char *port)
iov[0].iov_len = sizeof(hdr);
niov = 1;
for (ai = res; ai && niov < NIOV; ai = ai->ai_next) {
hdr.size += sizeof(*ai) + ai->ai_addrlen;
static const char zeros[ 8 ] = { 0, 0, 0, 0, 0, 0, 0, 0 };
size_t padded = ROUND_UP_LENGTH(ai->ai_addrlen);
hdr.size += sizeof(*ai) + padded;
iov[niov].iov_base = (char*)ai;
iov[niov].iov_len = sizeof(*ai);
niov++;
iov[niov].iov_base = (char*)ai->ai_addr;
iov[niov].iov_len = ai->ai_addrlen;
niov++;
if (padded != ai->ai_addrlen) {
/* padding */
iov[niov].iov_base = (char*)zeros;
iov[niov].iov_len = padded - ai->ai_addrlen;
niov++;
}
}
writev(fd, iov, niov);
if (res) freeaddrinfo(res);
Expand Down