Skip to content

Commit e3d4d22

Browse files
committed
src/conf.c, src/ssl.c, wolfcrypt/src/asn.c, wolfssl/wolfcrypt/asn.h: fixes for invalid-pointer-pair memory errors reported by clang sanitizer with detect_invalid_pointer_pairs=2 in ASAN_OPTIONS.
1 parent 5b1d2d7 commit e3d4d22

4 files changed

Lines changed: 27 additions & 11 deletions

File tree

src/conf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ WOLFSSL_TXT_DB *wolfSSL_TXT_DB_read(WOLFSSL_BIO *in, int num)
9898
if (*idx == '#')
9999
continue;
100100
*lineEnd = '\0';
101-
strBuf = (char*)XMALLOC(fieldsSz + lineEnd - idx + 1, NULL,
101+
strBuf = (char*)XMALLOC(fieldsSz + (lineEnd - idx) + 1, NULL,
102102
DYNAMIC_TYPE_OPENSSL);
103103
if (!strBuf) {
104104
WOLFSSL_MSG("malloc error");

src/ssl.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11746,17 +11746,23 @@ int wolfSSL_OCSP_parse_url(const char* url, char** host, char** port,
1174611746
if (upath != NULL && uport >= upath)
1174711747
goto err;
1174811748
XFREE(*port, NULL, DYNAMIC_TYPE_OPENSSL);
11749-
*port = CopyString(uport, upath != NULL ? (int)(upath - uport) : -1,
11750-
NULL, DYNAMIC_TYPE_OPENSSL);
11749+
if (upath)
11750+
*port = CopyString(uport, (int)(upath - uport), NULL,
11751+
DYNAMIC_TYPE_OPENSSL);
11752+
else
11753+
*port = CopyString(uport, -1, NULL, DYNAMIC_TYPE_OPENSSL);
1175111754
if (*port == NULL)
1175211755
goto err;
1175311756
hostEnd = uport - 1;
1175411757
}
1175511758
else
1175611759
hostEnd = upath;
1175711760

11758-
*host = CopyString(u, hostEnd != NULL ? (int)(hostEnd - u) : -1, NULL,
11759-
DYNAMIC_TYPE_OPENSSL);
11761+
if (hostEnd)
11762+
*host = CopyString(u, (int)(hostEnd - u), NULL, DYNAMIC_TYPE_OPENSSL);
11763+
else
11764+
*host = CopyString(u, -1, NULL, DYNAMIC_TYPE_OPENSSL);
11765+
1176011766
if (*host == NULL)
1176111767
goto err;
1176211768

wolfcrypt/src/asn.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21417,6 +21417,7 @@ static int CheckCertSignature_ex(const byte* cert, word32 certSz, void* heap,
2141721417
/* Parse certificate request. */
2141821418
ret = GetASN_Items(certReqASN, dataASN, certReqASN_Length, 1, cert,
2141921419
&idx, certSz);
21420+
2142021421
if (ret == 0) {
2142121422
/* Store the data for verification in the certificate. */
2142221423
tbs = GetASNItem_Addr(dataASN[CERTREQASN_IDX_INFO_SEQ], cert);
@@ -21427,11 +21428,14 @@ static int CheckCertSignature_ex(const byte* cert, word32 certSz, void* heap,
2142721428
dataASN[CERTREQASN_IDX_INFO_SUBJ_SEQ], cert);
2142821429
sigOID = dataASN[CERTREQASN_IDX_INFO_SIGALGO_OID].data.oid.sum;
2142921430
#ifdef WC_RSA_PSS
21430-
sigParams = GetASNItem_Addr(dataASN[X509CERTASN_IDX_SIGALGO_PARAMS],
21431-
cert);
21432-
sigParamsSz =
21433-
GetASNItem_Length(dataASN[X509CERTASN_IDX_SIGALGO_PARAMS],
21434-
cert);
21431+
if (GetASNItem_HaveData(dataASN[X509CERTASN_IDX_SIGALGO_PARAMS])) {
21432+
sigParams =
21433+
GetASNItem_Addr(dataASN[X509CERTASN_IDX_SIGALGO_PARAMS],
21434+
cert);
21435+
sigParamsSz =
21436+
GetASNItem_Length(dataASN[X509CERTASN_IDX_SIGALGO_PARAMS],
21437+
cert);
21438+
}
2143521439
#endif
2143621440
GetASN_GetConstRef(&dataASN[CERTREQASN_IDX_INFO_SIGNATURE], &sig,
2143721441
&sigSz);
@@ -34360,7 +34364,7 @@ int ParseCRL(RevokedCert* rcert, DecodedCRL* dcrl, const byte* buff, word32 sz,
3436034364
GetASNItem_DataIdx(dataASN[CRLASN_IDX_TBS_REVOKEDCERTS], buff),
3436134365
GetASNItem_EndIdx(dataASN[CRLASN_IDX_TBS_REVOKEDCERTS], buff));
3436234366
}
34363-
if (ret == 0) {
34367+
if ((ret == 0) && GetASNItem_HaveIdx(dataASN[CRLASN_IDX_TBS_EXT_SEQ])) {
3436434368
/* Parse the extensions - starting after SEQUENCE OF. */
3436534369
ret = ParseCRL_Extensions(dcrl, buff,
3436634370
GetASNItem_DataIdx(dataASN[CRLASN_IDX_TBS_EXT_SEQ], buff),

wolfssl/wolfcrypt/asn.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,9 @@ WOLFSSL_LOCAL void SetASN_OID(ASNSetData *dataASN, int oid, int oidType);
651651
((dataASN).length + (word32)((dataASN).data.buffer.data - (in)) - \
652652
(dataASN).offset)
653653

654+
#define GetASNItem_HaveData(dataASN) \
655+
((dataASN).data.buffer.data != NULL)
656+
654657
/* Get the index of a BER item's data.
655658
*
656659
* @param [in] dataASN Dynamic ASN data item.
@@ -660,6 +663,9 @@ WOLFSSL_LOCAL void SetASN_OID(ASNSetData *dataASN, int oid, int oidType);
660663
#define GetASNItem_DataIdx(dataASN, in) \
661664
(word32)((dataASN).data.ref.data - (in))
662665

666+
#define GetASNItem_HaveIdx(dataASN) \
667+
((dataASN).data.ref.data != NULL)
668+
663669
/* Get the end index of a BER item - index of the start of the next item.
664670
*
665671
* @param [in] dataASN Dynamic ASN data item.

0 commit comments

Comments
 (0)