Skip to content

Commit

Permalink
Update BoringSSL to 6ba98ff60144f60aba589b4d6121689528fbae76 (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasa committed Nov 13, 2019
1 parent c277611 commit 63e61ed
Show file tree
Hide file tree
Showing 157 changed files with 1,231 additions and 11,514 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Expand Up @@ -22,7 +22,7 @@ import PackageDescription
// Sources/CNIOBoringSSL directory. The source repository is at
// https://boringssl.googlesource.com/boringssl.
//
// BoringSSL Commit: 4ca15d5dcbe6e8051a4654df7c971ea8307abfe0
// BoringSSL Commit: 6ba98ff60144f60aba589b4d6121689528fbae76

let package = Package(
name: "swift-nio-ssl",
Expand Down
7 changes: 3 additions & 4 deletions Sources/CNIOBoringSSL/crypto/asn1/a_time.c
Expand Up @@ -60,7 +60,6 @@
#include <time.h>

#include <CNIOBoringSSL_asn1t.h>
#include <CNIOBoringSSL_buf.h>
#include <CNIOBoringSSL_err.h>
#include <CNIOBoringSSL_mem.h>

Expand Down Expand Up @@ -143,11 +142,11 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t,
str = (char *)ret->data;
/* Work out the century and prepend */
if (t->data[0] >= '5')
BUF_strlcpy(str, "19", newlen);
OPENSSL_strlcpy(str, "19", newlen);
else
BUF_strlcpy(str, "20", newlen);
OPENSSL_strlcpy(str, "20", newlen);

BUF_strlcat(str, (char *)t->data, newlen);
OPENSSL_strlcat(str, (char *)t->data, newlen);

done:
if (out != NULL && *out == NULL)
Expand Down
7 changes: 3 additions & 4 deletions Sources/CNIOBoringSSL/crypto/bio/connect.c
Expand Up @@ -74,7 +74,6 @@ OPENSSL_MSVC_PRAGMA(warning(push, 3))
OPENSSL_MSVC_PRAGMA(warning(pop))
#endif

#include <CNIOBoringSSL_buf.h>
#include <CNIOBoringSSL_err.h>
#include <CNIOBoringSSL_mem.h>

Expand Down Expand Up @@ -149,7 +148,7 @@ static int split_host_and_port(char **out_host, char **out_port, const char *nam
}
}

*out_host = BUF_strndup(host, host_len);
*out_host = OPENSSL_strndup(host, host_len);
if (*out_host == NULL) {
return 0;
}
Expand Down Expand Up @@ -429,13 +428,13 @@ static long conn_ctrl(BIO *bio, int cmd, long num, void *ptr) {
bio->init = 1;
if (num == 0) {
OPENSSL_free(data->param_hostname);
data->param_hostname = BUF_strdup(ptr);
data->param_hostname = OPENSSL_strdup(ptr);
if (data->param_hostname == NULL) {
ret = 0;
}
} else if (num == 1) {
OPENSSL_free(data->param_port);
data->param_port = BUF_strdup(ptr);
data->param_port = OPENSSL_strdup(ptr);
if (data->param_port == NULL) {
ret = 0;
}
Expand Down
1 change: 0 additions & 1 deletion Sources/CNIOBoringSSL/crypto/bio/fd.c
Expand Up @@ -70,7 +70,6 @@ OPENSSL_MSVC_PRAGMA(warning(push, 3))
OPENSSL_MSVC_PRAGMA(warning(pop))
#endif

#include <CNIOBoringSSL_buf.h>
#include <CNIOBoringSSL_err.h>
#include <CNIOBoringSSL_mem.h>

Expand Down
11 changes: 5 additions & 6 deletions Sources/CNIOBoringSSL/crypto/bio/file.c
Expand Up @@ -79,7 +79,6 @@
#include <stdio.h>
#include <string.h>

#include <CNIOBoringSSL_buf.h>
#include <CNIOBoringSSL_err.h>
#include <CNIOBoringSSL_mem.h>

Expand Down Expand Up @@ -208,16 +207,16 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
b->shutdown = (int)num & BIO_CLOSE;
if (num & BIO_FP_APPEND) {
if (num & BIO_FP_READ) {
BUF_strlcpy(p, "a+", sizeof(p));
OPENSSL_strlcpy(p, "a+", sizeof(p));
} else {
BUF_strlcpy(p, "a", sizeof(p));
OPENSSL_strlcpy(p, "a", sizeof(p));
}
} else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) {
BUF_strlcpy(p, "r+", sizeof(p));
OPENSSL_strlcpy(p, "r+", sizeof(p));
} else if (num & BIO_FP_WRITE) {
BUF_strlcpy(p, "w", sizeof(p));
OPENSSL_strlcpy(p, "w", sizeof(p));
} else if (num & BIO_FP_READ) {
BUF_strlcpy(p, "r", sizeof(p));
OPENSSL_strlcpy(p, "r", sizeof(p));
} else {
OPENSSL_PUT_ERROR(BIO, BIO_R_BAD_FOPEN_MODE);
ret = 0;
Expand Down
1 change: 0 additions & 1 deletion Sources/CNIOBoringSSL/crypto/bio/pair.c
Expand Up @@ -55,7 +55,6 @@
#include <assert.h>
#include <string.h>

#include <CNIOBoringSSL_buf.h>
#include <CNIOBoringSSL_err.h>
#include <CNIOBoringSSL_mem.h>

Expand Down
79 changes: 10 additions & 69 deletions Sources/CNIOBoringSSL/crypto/buf/buf.c
Expand Up @@ -132,6 +132,10 @@ size_t BUF_MEM_grow_clean(BUF_MEM *buf, size_t len) {
}

int BUF_MEM_append(BUF_MEM *buf, const void *in, size_t len) {
// Work around a C language bug. See https://crbug.com/1019588.
if (len == 0) {
return 1;
}
size_t new_len = buf->length + len;
if (new_len < len) {
OPENSSL_PUT_ERROR(BUF, ERR_R_OVERFLOW);
Expand All @@ -145,87 +149,24 @@ int BUF_MEM_append(BUF_MEM *buf, const void *in, size_t len) {
return 1;
}

char *BUF_strdup(const char *str) {
if (str == NULL) {
return NULL;
}

return BUF_strndup(str, strlen(str));
}
char *BUF_strdup(const char *str) { return OPENSSL_strdup(str); }

size_t BUF_strnlen(const char *str, size_t max_len) {
size_t i;

for (i = 0; i < max_len; i++) {
if (str[i] == 0) {
break;
}
}

return i;
return OPENSSL_strnlen(str, max_len);
}

char *BUF_strndup(const char *str, size_t size) {
char *ret;
size_t alloc_size;

if (str == NULL) {
return NULL;
}

size = BUF_strnlen(str, size);

alloc_size = size + 1;
if (alloc_size < size) {
// overflow
OPENSSL_PUT_ERROR(BUF, ERR_R_MALLOC_FAILURE);
return NULL;
}
ret = OPENSSL_malloc(alloc_size);
if (ret == NULL) {
OPENSSL_PUT_ERROR(BUF, ERR_R_MALLOC_FAILURE);
return NULL;
}

OPENSSL_memcpy(ret, str, size);
ret[size] = '\0';
return ret;
return OPENSSL_strndup(str, size);
}

size_t BUF_strlcpy(char *dst, const char *src, size_t dst_size) {
size_t l = 0;

for (; dst_size > 1 && *src; dst_size--) {
*dst++ = *src++;
l++;
}

if (dst_size) {
*dst = 0;
}

return l + strlen(src);
return OPENSSL_strlcpy(dst, src, dst_size);
}

size_t BUF_strlcat(char *dst, const char *src, size_t dst_size) {
size_t l = 0;
for (; dst_size > 0 && *dst; dst_size--, dst++) {
l++;
}
return l + BUF_strlcpy(dst, src, dst_size);
return OPENSSL_strlcat(dst, src, dst_size);
}

void *BUF_memdup(const void *data, size_t size) {
if (size == 0) {
return NULL;
}

void *ret = OPENSSL_malloc(size);
if (ret == NULL) {
OPENSSL_PUT_ERROR(BUF, ERR_R_MALLOC_FAILURE);
return NULL;
}

OPENSSL_memcpy(ret, data, size);
return ret;
return OPENSSL_memdup(data, size);
}
3 changes: 1 addition & 2 deletions Sources/CNIOBoringSSL/crypto/bytestring/cbb.c
Expand Up @@ -18,7 +18,6 @@
#include <limits.h>
#include <string.h>

#include <CNIOBoringSSL_buf.h>
#include <CNIOBoringSSL_mem.h>

#include "../internal.h"
Expand Down Expand Up @@ -649,7 +648,7 @@ int CBB_flush_asn1_set_of(CBB *cbb) {
// remain valid as we rewrite |cbb|.
int ret = 0;
size_t buf_len = CBB_len(cbb);
uint8_t *buf = BUF_memdup(CBB_data(cbb), buf_len);
uint8_t *buf = OPENSSL_memdup(CBB_data(cbb), buf_len);
CBS *children = OPENSSL_malloc(num_children * sizeof(CBS));
if (buf == NULL || children == NULL) {
goto err;
Expand Down
5 changes: 2 additions & 3 deletions Sources/CNIOBoringSSL/crypto/bytestring/cbs.c
Expand Up @@ -12,7 +12,6 @@
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */

#include <CNIOBoringSSL_buf.h>
#include <CNIOBoringSSL_mem.h>
#include <CNIOBoringSSL_bytestring.h>

Expand Down Expand Up @@ -61,7 +60,7 @@ int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len) {
if (cbs->len == 0) {
return 1;
}
*out_ptr = BUF_memdup(cbs->data, cbs->len);
*out_ptr = OPENSSL_memdup(cbs->data, cbs->len);
if (*out_ptr == NULL) {
return 0;
}
Expand All @@ -73,7 +72,7 @@ int CBS_strdup(const CBS *cbs, char **out_ptr) {
if (*out_ptr != NULL) {
OPENSSL_free(*out_ptr);
}
*out_ptr = BUF_strndup((const char*)cbs->data, cbs->len);
*out_ptr = OPENSSL_strndup((const char*)cbs->data, cbs->len);
return (*out_ptr != NULL);
}

Expand Down
Expand Up @@ -1490,9 +1490,9 @@ ChaCha20_neon:
.size ChaCha20_neon,.-ChaCha20_neon
.comm OPENSSL_armcap_P,4,4
#endif
.section .note.GNU-stack,"",%progbits
#endif
#endif // !OPENSSL_NO_ASM
.section .note.GNU-stack,"",%progbits
#endif // defined(__arm__) && defined(__linux__)
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
Expand Down
Expand Up @@ -1982,9 +1982,9 @@ ChaCha20_512_neon:
ldp x29,x30,[sp],#96
ret
.size ChaCha20_512_neon,.-ChaCha20_512_neon
.section .note.GNU-stack,"",%progbits
#endif
#endif // !OPENSSL_NO_ASM
.section .note.GNU-stack,"",%progbits
#endif // defined(__aarch64__) && defined(__linux__)
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
Expand Down
2 changes: 1 addition & 1 deletion Sources/CNIOBoringSSL/crypto/chacha/chacha-x86.linux.x86.S
Expand Up @@ -973,8 +973,8 @@ ChaCha20_ssse3:
.byte 44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32
.byte 60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111
.byte 114,103,62,0
.section .note.GNU-stack,"",@progbits
#endif
.section .note.GNU-stack,"",@progbits
#endif // defined(__i386__) && defined(__linux__)
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
Expand Down
Expand Up @@ -1631,8 +1631,8 @@ ChaCha20_8x:
.byte 0xf3,0xc3
.cfi_endproc
.size ChaCha20_8x,.-ChaCha20_8x
.section .note.GNU-stack,"",@progbits
#endif
.section .note.GNU-stack,"",@progbits
#endif // defined(__x86_64__) && defined(__linux__)
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
Expand Down
Expand Up @@ -3077,8 +3077,8 @@ aes256gcmsiv_kdf:
.byte 0xf3,0xc3
.cfi_endproc
.size aes256gcmsiv_kdf, .-aes256gcmsiv_kdf
.section .note.GNU-stack,"",@progbits
#endif
.section .note.GNU-stack,"",@progbits
#endif // defined(__x86_64__) && defined(__linux__)
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
Expand Down
Expand Up @@ -8985,8 +8985,8 @@ seal_avx2_short_tail:
vzeroupper
jmp seal_sse_tail_16
.cfi_endproc
.section .note.GNU-stack,"",@progbits
#endif
.section .note.GNU-stack,"",@progbits
#endif // defined(__x86_64__) && defined(__linux__)
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
Expand Down
1 change: 0 additions & 1 deletion Sources/CNIOBoringSSL/crypto/cpu-arm-linux.c
Expand Up @@ -21,7 +21,6 @@
#include <unistd.h>

#include <CNIOBoringSSL_arm_arch.h>
#include <CNIOBoringSSL_buf.h>
#include <CNIOBoringSSL_mem.h>

#include "cpu-arm-linux.h"
Expand Down
10 changes: 9 additions & 1 deletion Sources/CNIOBoringSSL/crypto/cpu-intel.c
Expand Up @@ -123,9 +123,17 @@ static uint64_t OPENSSL_xgetbv(uint32_t xcr) {
// and |out[1]|. See the comment in |OPENSSL_cpuid_setup| about this.
static void handle_cpu_env(uint32_t *out, const char *in) {
const int invert = in[0] == '~';
const int hex = in[invert] == '0' && in[invert+1] == 'x';

int sscanf_result;
uint64_t v;
if (hex) {
sscanf_result = sscanf(in + invert + 2, "%" PRIx64, &v);
} else {
sscanf_result = sscanf(in + invert, "%" PRIu64, &v);
}

if (!sscanf(in + invert, "%" PRIu64, &v)) {
if (!sscanf_result) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/CNIOBoringSSL/crypto/curve25519/asm/x25519-asm-arm.S
Expand Up @@ -2131,11 +2131,11 @@ mov sp,r12
vpop {q4,q5,q6,q7}
bx lr

#endif /* !OPENSSL_NO_ASM && __arm__ && !__APPLE__ */

#if defined(__ELF__)
.section .note.GNU-stack,"",%progbits
#endif

#endif /* !OPENSSL_NO_ASM && __arm__ && !__APPLE__ */
#endif // defined(__arm__) && defined(__linux__)
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
Expand Down
3 changes: 1 addition & 2 deletions Sources/CNIOBoringSSL/crypto/dh/dh.c
Expand Up @@ -59,7 +59,6 @@
#include <string.h>

#include <CNIOBoringSSL_bn.h>
#include <CNIOBoringSSL_buf.h>
#include <CNIOBoringSSL_err.h>
#include <CNIOBoringSSL_ex_data.h>
#include <CNIOBoringSSL_mem.h>
Expand Down Expand Up @@ -476,7 +475,7 @@ static int int_dh_param_copy(DH *to, const DH *from, int is_x942) {
to->seedlen = 0;

if (from->seed) {
to->seed = BUF_memdup(from->seed, from->seedlen);
to->seed = OPENSSL_memdup(from->seed, from->seedlen);
if (!to->seed) {
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/CNIOBoringSSL/crypto/dsa/dsa.c
Expand Up @@ -256,7 +256,7 @@ int DSA_generate_parameters_ex(DSA *dsa, unsigned bits, const uint8_t *seed_in,
// Find q.
for (;;) {
// step 1
if (!BN_GENCB_call(cb, 0, m++)) {
if (!BN_GENCB_call(cb, BN_GENCB_GENERATED, m++)) {
goto err;
}

Expand Down Expand Up @@ -319,7 +319,7 @@ int DSA_generate_parameters_ex(DSA *dsa, unsigned bits, const uint8_t *seed_in,
n = (bits - 1) / 160;

for (;;) {
if ((counter != 0) && !BN_GENCB_call(cb, 0, counter)) {
if ((counter != 0) && !BN_GENCB_call(cb, BN_GENCB_GENERATED, counter)) {
goto err;
}

Expand Down

0 comments on commit 63e61ed

Please sign in to comment.