Skip to content

Commit

Permalink
Merge branch 'main' into far3-dev-tests
Browse files Browse the repository at this point in the history
* main:
  OpenSSL: fix x86 build
  OpenSSL: update to 3.2.2
  Fix code page storing
  Fix unexpected session closure when clicking Abort
  Fix sending long FTP command
  Fix FTP to work with encodings correctly
  • Loading branch information
michaellukashov committed Jun 20, 2024
2 parents a1c9d83 + 6163b46 commit d2d1e0e
Show file tree
Hide file tree
Showing 89 changed files with 2,573 additions and 2,039 deletions.
10 changes: 7 additions & 3 deletions libs/openssl-3/crypto/bio/bio_lib.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
Expand Down Expand Up @@ -965,8 +965,12 @@ static int bio_wait(BIO *bio, time_t max_time, unsigned int nap_milliseconds)
return 1;

#ifndef OPENSSL_NO_SOCK
if (BIO_get_fd(bio, &fd) > 0 && fd < FD_SETSIZE)
return BIO_socket_wait(fd, BIO_should_read(bio), max_time);
if (BIO_get_fd(bio, &fd) > 0) {
int ret = BIO_socket_wait(fd, BIO_should_read(bio), max_time);

if (ret != -1)
return ret;
}
#endif
/* fall back to polling since no sockets are available */

Expand Down
6 changes: 5 additions & 1 deletion libs/openssl-3/crypto/bio/bio_sock.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
Expand Down Expand Up @@ -435,7 +435,11 @@ int BIO_socket_wait(int fd, int for_read, time_t max_time)
struct timeval tv;
time_t now;

#ifdef _WIN32
if ((SOCKET)fd == INVALID_SOCKET)
#else
if (fd < 0 || fd >= FD_SETSIZE)
#endif
return -1;
if (max_time == 0)
return 1;
Expand Down
12 changes: 8 additions & 4 deletions libs/openssl-3/crypto/bio/bss_conn.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
Expand Down Expand Up @@ -110,7 +110,7 @@ static int conn_create_dgram_bio(BIO *b, BIO_CONNECT *c)

static int conn_state(BIO *b, BIO_CONNECT *c)
{
int ret = -1, i;
int ret = -1, i, opts;
BIO_info_cb *cb = NULL;

if (c->info_callback != NULL)
Expand Down Expand Up @@ -188,8 +188,12 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
case BIO_CONN_S_CONNECT:
BIO_clear_retry_flags(b);
ERR_set_mark();
ret = BIO_connect(b->num, BIO_ADDRINFO_address(c->addr_iter),
BIO_SOCK_KEEPALIVE | c->connect_mode);

opts = c->connect_mode;
if (BIO_ADDRINFO_socktype(c->addr_iter) == SOCK_STREAM)
opts |= BIO_SOCK_KEEPALIVE;

ret = BIO_connect(b->num, BIO_ADDRINFO_address(c->addr_iter), opts);
b->retry_reason = 0;
if (ret == 0) {
if (BIO_sock_should_retry(ret)) {
Expand Down
34 changes: 26 additions & 8 deletions libs/openssl-3/crypto/bio/bss_dgram.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
#undef NO_RECVMSG
#define NO_RECVMSG
# endif
# if defined(__ANDROID_API__) && __ANDROID_API__ < 21
# undef NO_RECVMMSG
# define NO_RECVMMSG
# endif
# if !defined(M_METHOD)
# if defined(OPENSSL_SYS_WINDOWS) && defined(BIO_HAVE_WSAMSG) && !defined(NO_WSARECVMSG)
# define M_METHOD M_METHOD_WSARECVMSG
Expand Down Expand Up @@ -556,6 +560,8 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
socklen_t addr_len;
BIO_ADDR addr;
# endif
struct sockaddr_storage ss;
socklen_t ss_len = sizeof(ss);

data = (bio_dgram_data *)b->ptr;

Expand All @@ -573,6 +579,10 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
b->shutdown = (int)num;
b->init = 1;
dgram_update_local_addr(b);
if (getpeername(b->num, (struct sockaddr *)&ss, &ss_len) == 0) {
BIO_ADDR_make(&data->peer, BIO_ADDR_sockaddr((BIO_ADDR *)&ss));
data->connected = 1;
}
# if defined(SUPPORT_LOCAL_ADDR)
if (data->local_addr_enabled) {
if (enable_local_addr(b, 1) < 1)
Expand Down Expand Up @@ -1063,19 +1073,27 @@ static void translate_msg_win(BIO *b, WSAMSG *mh, WSABUF *iov,
static void translate_msg(BIO *b, struct msghdr *mh, struct iovec *iov,
unsigned char *control, BIO_MSG *msg)
{
bio_dgram_data *data;

iov->iov_base = msg->data;
iov->iov_len = msg->data_len;

/* macOS requires msg_namelen be 0 if msg_name is NULL */
mh->msg_name = msg->peer != NULL ? &msg->peer->sa : NULL;
if (msg->peer != NULL && dgram_get_sock_family(b) == AF_INET)
mh->msg_namelen = sizeof(struct sockaddr_in);
data = (bio_dgram_data *)b->ptr;
if (data->connected == 0) {
/* macOS requires msg_namelen be 0 if msg_name is NULL */
mh->msg_name = msg->peer != NULL ? &msg->peer->sa : NULL;
if (msg->peer != NULL && dgram_get_sock_family(b) == AF_INET)
mh->msg_namelen = sizeof(struct sockaddr_in);
# if OPENSSL_USE_IPV6
else if (msg->peer != NULL && dgram_get_sock_family(b) == AF_INET6)
mh->msg_namelen = sizeof(struct sockaddr_in6);
else if (msg->peer != NULL && dgram_get_sock_family(b) == AF_INET6)
mh->msg_namelen = sizeof(struct sockaddr_in6);
# endif
else
else
mh->msg_namelen = 0;
} else {
mh->msg_name = NULL;
mh->msg_namelen = 0;
}

mh->msg_iov = iov;
mh->msg_iovlen = 1;
Expand Down Expand Up @@ -1174,7 +1192,7 @@ static int pack_local(BIO *b, MSGHDR_TYPE *mh, const BIO_ADDR *local) {
cmsg->cmsg_type = IP_PKTINFO;

info = (struct in_pktinfo *)BIO_CMSG_DATA(cmsg);
# if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_CYGWIN)
# if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_CYGWIN) && !defined(__FreeBSD__)
info->ipi_spec_dst = local->s_in.sin_addr;
# endif
info->ipi_addr.s_addr = 0;
Expand Down
1 change: 1 addition & 0 deletions libs/openssl-3/crypto/bn/bn_const.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <openssl/bn.h>
#include "crypto/bn_dh.h"
#include "bn_local.h" // WINSCP

#define COPY_BN(dst, src) (dst != NULL) ? BN_copy(dst, &src) : BN_dup(&src)

Expand Down
53 changes: 47 additions & 6 deletions libs/openssl-3/crypto/bn/bn_lib.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
Expand Down Expand Up @@ -708,14 +708,29 @@ int BN_ucmp(const BIGNUM *a, const BIGNUM *b)
int i;
BN_ULONG t1, t2, *ap, *bp;

ap = a->d;
bp = b->d;

if (BN_get_flags(a, BN_FLG_CONSTTIME)
&& a->top == b->top) {
int res = 0;

for (i = 0; i < b->top; i++) {
res = constant_time_select_int(constant_time_lt_bn(ap[i], bp[i]),
-1, res);
res = constant_time_select_int(constant_time_lt_bn(bp[i], ap[i]),
1, res);
}
return res;
}

bn_check_top(a);
bn_check_top(b);

i = a->top - b->top;
if (i != 0)
return i;
ap = a->d;
bp = b->d;

for (i = a->top - 1; i >= 0; i--) {
t1 = ap[i];
t2 = bp[i];
Expand Down Expand Up @@ -827,11 +842,10 @@ int BN_is_bit_set(const BIGNUM *a, int n)
return (int)(((a->d[i]) >> j) & ((BN_ULONG)1));
}

int BN_mask_bits(BIGNUM *a, int n)
int ossl_bn_mask_bits_fixed_top(BIGNUM *a, int n)
{
int b, w;

bn_check_top(a);
if (n < 0)
return 0;

Expand All @@ -845,10 +859,21 @@ int BN_mask_bits(BIGNUM *a, int n)
a->top = w + 1;
a->d[w] &= ~(BN_MASK2 << b);
}
bn_correct_top(a);
a->flags |= BN_FLG_FIXED_TOP;
return 1;
}

int BN_mask_bits(BIGNUM *a, int n)
{
int ret;

bn_check_top(a);
ret = ossl_bn_mask_bits_fixed_top(a, n);
if (ret)
bn_correct_top(a);
return ret;
}

void BN_set_negative(BIGNUM *a, int b)
{
if (b && !BN_is_zero(a))
Expand Down Expand Up @@ -1022,6 +1047,22 @@ int BN_is_word(const BIGNUM *a, const BN_ULONG w)
return BN_abs_is_word(a, w) && (!w || !a->neg);
}

int ossl_bn_is_word_fixed_top(const BIGNUM *a, const BN_ULONG w)
{
int res, i;
const BN_ULONG *ap = a->d;

if (a->neg || a->top == 0)
return 0;

res = constant_time_select_int(constant_time_eq_bn(ap[0], w), 1, 0);

for (i = 1; i < a->top; i++)
res = constant_time_select_int(constant_time_is_zero_bn(ap[i]),
res, 0);
return res;
}

int BN_is_odd(const BIGNUM *a)
{
return (a->top > 0) && (a->d[0] & 1);
Expand Down
Loading

0 comments on commit d2d1e0e

Please sign in to comment.