@@ -23587,12 +23587,13 @@ int wolfSSL_CTX_set_alpn_protos(WOLFSSL_CTX *ctx, const unsigned char *p,
2358723587int 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}
0 commit comments