Skip to content

Commit 71afa73

Browse files
committed
Refactor : fix some buggy logic + cleaned code
1 parent 6c6984d commit 71afa73

4 files changed

Lines changed: 15 additions & 17 deletions

File tree

src/bio.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,13 +2077,6 @@ long wolfSSL_BIO_set_nbio(WOLFSSL_BIO* bio, long on)
20772077
return WOLFSSL_SUCCESS;
20782078
}
20792079

2080-
/* Returns a unique index for a new custom BIO type.
2081-
* In OpenSSL, custom BIO types start at BIO_TYPE_START (128|0x0200).
2082-
* wolfSSL uses a simpler scheme starting at 128.
2083-
*
2084-
* @return New unique BIO type index on success.
2085-
* @return -1 when the index space is exhausted.
2086-
*/
20872080
int wolfSSL_BIO_get_new_index(void)
20882081
{
20892082
static int bio_type_idx = WOLFSSL_BIO_TYPE_START;
@@ -2092,7 +2085,7 @@ int wolfSSL_BIO_get_new_index(void)
20922085
WOLFSSL_ENTER("wolfSSL_BIO_get_new_index");
20932086

20942087
idx = bio_type_idx;
2095-
if (idx > WOLFSSL_BIO_TYPE_MAX + WOLFSSL_BIO_TYPE_START) {
2088+
if (idx > WOLFSSL_BIO_TYPE_MAX) {
20962089
WOLFSSL_MSG("BIO type index space exhausted");
20972090
return -1;
20982091
}

src/ssl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10758,7 +10758,7 @@ const char* wolfSSL_OpenSSL_version(int type)
1075810758
case OPENSSL_PLATFORM:
1075910759
return "platform: information not available";
1076010760
case OPENSSL_DIR:
10761-
return "OPENSSLDIR: \"\"";
10761+
return "OPENSSLDIR: N/A";
1076210762
case OPENSSL_ENGINES_DIR:
1076310763
return "ENGINESDIR: N/A";
1076410764
default:
@@ -10770,8 +10770,8 @@ const char* wolfSSL_OpenSSL_version(void)
1077010770
{
1077110771
return "wolfSSL " LIBWOLFSSL_VERSION_STRING;
1077210772
}
10773-
#endif /* WOLFSSL_QT */
10774-
#endif
10773+
#endif /* OPENSSL_VERSION_NUMBER >= 0x10100000L */
10774+
#endif /* OPENSSL_EXTRA */
1077510775

1077610776

1077710777
/* current library version in hex */

tests/api/test_ossl_bio.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,23 +1811,26 @@ int test_wolfSSL_BIO_get_new_index(void)
18111811
BIO_METHOD* meth = NULL;
18121812
BIO* bio = NULL;
18131813

1814-
/* Get three consecutive indices - should be unique and >= 128 */
1814+
/* Get three consecutive indices - should be unique and in valid range */
18151815
idx1 = BIO_get_new_index();
18161816
idx2 = BIO_get_new_index();
18171817
idx3 = BIO_get_new_index();
18181818

18191819
ExpectIntGE(idx1, BIO_TYPE_START);
1820+
ExpectIntLE(idx1, WOLFSSL_BIO_TYPE_MAX);
18201821
ExpectIntGE(idx2, BIO_TYPE_START);
1822+
ExpectIntLE(idx2, WOLFSSL_BIO_TYPE_MAX);
18211823
ExpectIntGE(idx3, BIO_TYPE_START);
1824+
ExpectIntLE(idx3, WOLFSSL_BIO_TYPE_MAX);
18221825

18231826
/* Each index must be unique */
18241827
ExpectIntNE(idx1, idx2);
18251828
ExpectIntNE(idx2, idx3);
18261829
ExpectIntNE(idx1, idx3);
18271830

1828-
/* Indices should be sequential */
1829-
ExpectIntEQ(idx2, idx1 + 1);
1830-
ExpectIntEQ(idx3, idx2 + 1);
1831+
/* Each consecutive call must return a strictly increasing value */
1832+
ExpectIntGT(idx2, idx1);
1833+
ExpectIntGT(idx3, idx2);
18311834

18321835
/* Use returned index with BIO_meth_new */
18331836
ExpectNotNull(meth = BIO_meth_new(idx1, "custom_test"));

wolfcrypt/src/evp_pk.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,8 +1926,10 @@ int wolfSSL_i2d_PUBKEY_bio(WOLFSSL_BIO* bio, WOLFSSL_EVP_PKEY* key)
19261926
return WOLFSSL_FAILURE;
19271927
}
19281928

1929+
/* Let wolfSSL_i2d_PUBKEY allocate the buffer (pass NULL to trigger
1930+
* internal allocation). We free it ourselves after writing to the BIO. */
19291931
derSz = wolfSSL_i2d_PUBKEY(key, &der);
1930-
if (derSz <= 0) {
1932+
if (derSz <= 0 || der == NULL) {
19311933
WOLFSSL_MSG("wolfSSL_i2d_PUBKEY failed");
19321934
return WOLFSSL_FAILURE;
19331935
}
@@ -1939,7 +1941,7 @@ int wolfSSL_i2d_PUBKEY_bio(WOLFSSL_BIO* bio, WOLFSSL_EVP_PKEY* key)
19391941
ret = WOLFSSL_SUCCESS;
19401942

19411943
cleanup:
1942-
XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
1944+
XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
19431945
return ret;
19441946
}
19451947
#endif /* !NO_BIO */

0 commit comments

Comments
 (0)