Skip to content

Commit b0a5d2f

Browse files
authored
Merge pull request #8969 from SparkiDev/alpn_gcc_Os_fix
ALPN: don't use BIO
2 parents cf35abc + 70e53d1 commit b0a5d2f

2 files changed

Lines changed: 31 additions & 17 deletions

File tree

src/ssl.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23587,12 +23587,13 @@ int wolfSSL_CTX_set_alpn_protos(WOLFSSL_CTX *ctx, const unsigned char *p,
2358723587
int wolfSSL_set_alpn_protos(WOLFSSL* ssl,
2358823588
const unsigned char* p, unsigned int p_len)
2358923589
{
23590-
WOLFSSL_BIO* bio;
2359123590
char* pt = NULL;
23592-
23591+
unsigned int ptIdx;
2359323592
unsigned int sz;
2359423593
unsigned int idx = 0;
2359523594
int alpn_opt = WOLFSSL_ALPN_CONTINUE_ON_MISMATCH;
23595+
int ret;
23596+
2359623597
WOLFSSL_ENTER("wolfSSL_set_alpn_protos");
2359723598

2359823599
if (ssl == NULL || p_len <= 1) {
@@ -23606,8 +23607,9 @@ int wolfSSL_set_alpn_protos(WOLFSSL* ssl,
2360623607
#endif
2360723608
}
2360823609

23609-
bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
23610-
if (bio == NULL) {
23610+
/* Replacing leading number with trailing ',' and adding '\0'. */
23611+
pt = (char*)XMALLOC(p_len + 1, ssl->heap, DYNAMIC_TYPE_OPENSSL);
23612+
if (pt == NULL) {
2361123613
#if defined(WOLFSSL_ERROR_CODE_OPENSSL)
2361223614
/* 0 on success in OpenSSL, non-0 on failure in OpenSSL
2361323615
* the function reverses the return value convention.
@@ -23618,14 +23620,15 @@ int wolfSSL_set_alpn_protos(WOLFSSL* ssl,
2361823620
#endif
2361923621
}
2362023622

23623+
ptIdx = 0;
2362123624
/* convert into comma separated list */
2362223625
while (idx < p_len - 1) {
2362323626
unsigned int i;
2362423627

2362523628
sz = p[idx++];
2362623629
if (idx + sz > p_len) {
2362723630
WOLFSSL_MSG("Bad list format");
23628-
wolfSSL_BIO_free(bio);
23631+
XFREE(pt, ssl->heap, DYNAMIC_TYPE_OPENSSL);
2362923632
#if defined(WOLFSSL_ERROR_CODE_OPENSSL)
2363023633
/* 0 on success in OpenSSL, non-0 on failure in OpenSSL
2363123634
* the function reverses the return value convention.
@@ -23637,27 +23640,30 @@ int wolfSSL_set_alpn_protos(WOLFSSL* ssl,
2363723640
}
2363823641
if (sz > 0) {
2363923642
for (i = 0; i < sz; i++) {
23640-
wolfSSL_BIO_write(bio, &p[idx++], 1);
23643+
pt[ptIdx++] = p[idx++];
23644+
}
23645+
if (idx < p_len - 1) {
23646+
pt[ptIdx++] = ',';
2364123647
}
23642-
if (idx < p_len - 1)
23643-
wolfSSL_BIO_write(bio, ",", 1);
2364423648
}
2364523649
}
23646-
wolfSSL_BIO_write(bio, "\0", 1);
23650+
pt[ptIdx++] = '\0';
2364723651

2364823652
/* clears out all current ALPN extensions set */
2364923653
TLSX_Remove(&ssl->extensions, TLSX_APPLICATION_LAYER_PROTOCOL, ssl->heap);
2365023654

23651-
if ((sz = (unsigned int)wolfSSL_BIO_get_mem_data(bio, &pt)) > 0) {
23652-
wolfSSL_UseALPN(ssl, pt, sz, (byte) alpn_opt);
23653-
}
23654-
wolfSSL_BIO_free(bio);
23655+
ret = wolfSSL_UseALPN(ssl, pt, ptIdx, (byte)alpn_opt);
23656+
XFREE(pt, ssl->heap, DYNAMIC_TYPE_OPENSSL);
2365523657
#if defined(WOLFSSL_ERROR_CODE_OPENSSL)
2365623658
/* 0 on success in OpenSSL, non-0 on failure in OpenSSL
2365723659
* the function reverses the return value convention.
2365823660
*/
23661+
if (ret != WOLFSSL_SUCCESS)
23662+
return 1;
2365923663
return 0;
2366023664
#else
23665+
if (ret != WOLFSSL_SUCCESS)
23666+
return WOLFSSL_FAILURE;
2366123667
return WOLFSSL_SUCCESS;
2366223668
#endif
2366323669
}

tests/api.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13037,13 +13037,21 @@ static int test_wolfSSL_set_alpn_protos(void)
1303713037
server_cb.devId = testDevId;
1303813038

1303913039
/* use CTX_alpn_protos */
13040-
client_cb.ctx_ready = CTX_set_alpn_protos; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
13041-
server_cb.ctx_ready = CTX_set_alpn_protos; server_cb.ssl_ready = NULL; server_cb.on_result = verify_alpn_matching_http1;
13040+
client_cb.ctx_ready = CTX_set_alpn_protos;
13041+
client_cb.ssl_ready = NULL;
13042+
client_cb.on_result = NULL;
13043+
server_cb.ctx_ready = CTX_set_alpn_protos;
13044+
server_cb.ssl_ready = NULL;
13045+
server_cb.on_result = verify_alpn_matching_http1;
1304213046
test_wolfSSL_client_server(&client_cb, &server_cb);
1304313047

1304413048
/* use set_alpn_protos */
13045-
client_cb.ctx_ready = NULL; client_cb.ssl_ready = set_alpn_protos; client_cb.on_result = NULL;
13046-
server_cb.ctx_ready = NULL; server_cb.ssl_ready = set_alpn_protos; server_cb.on_result = verify_alpn_matching_spdy3;
13049+
client_cb.ctx_ready = NULL;
13050+
client_cb.ssl_ready = set_alpn_protos;
13051+
client_cb.on_result = NULL;
13052+
server_cb.ctx_ready = NULL;
13053+
server_cb.ssl_ready = set_alpn_protos;
13054+
server_cb.on_result = verify_alpn_matching_spdy3;
1304713055
test_wolfSSL_client_server(&client_cb, &server_cb);
1304813056

1304913057
res = TEST_SUCCESS;

0 commit comments

Comments
 (0)