Skip to content

Commit d052128

Browse files
committed
addressed review comments
1 parent 08876e2 commit d052128

5 files changed

Lines changed: 22 additions & 39 deletions

File tree

src/crl.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static int InitCRL_Entry(CRL_Entry* crle, DecodedCRL* dcrl, const byte* buff,
138138
crle->totalCerts = dcrl->totalCerts;
139139
crle->crlNumberSet = dcrl->crlNumberSet;
140140
if (crle->crlNumberSet) {
141-
XMEMCPY(crle->crlNumber, dcrl->crlNumber, CRL_MAX_NUM_HEX_STR_SZ);
141+
XMEMCPY(crle->crlNumber, dcrl->crlNumber, sizeof(crle->crlNumber));
142142
}
143143
crle->verified = verified;
144144
if (!verified) {
@@ -597,7 +597,7 @@ static void SetCrlInfo(CRL_Entry* entry, CrlInfo *info)
597597
info->nextDateFormat = entry->nextDateFormat;
598598
info->crlNumberSet = entry->crlNumberSet;
599599
if (info->crlNumberSet)
600-
XMEMCPY(info->crlNumber, entry->crlNumber, CRL_MAX_NUM_HEX_STR_SZ);
600+
XMEMCPY(info->crlNumber, entry->crlNumber, sizeof(entry->crlNumber));
601601
}
602602

603603
static void SetCrlInfoFromDecoded(DecodedCRL* entry, CrlInfo *info)
@@ -612,7 +612,7 @@ static void SetCrlInfoFromDecoded(DecodedCRL* entry, CrlInfo *info)
612612
info->nextDateFormat = entry->nextDateFormat;
613613
info->crlNumberSet = entry->crlNumberSet;
614614
if (info->crlNumberSet)
615-
XMEMCPY(info->crlNumber, entry->crlNumber, CRL_MAX_NUM_HEX_STR_SZ);
615+
XMEMCPY(info->crlNumber, entry->crlNumber, sizeof(entry->crlNumber));
616616
}
617617
#endif
618618

@@ -622,24 +622,24 @@ static void SetCrlInfoFromDecoded(DecodedCRL* entry, CrlInfo *info)
622622
static int CompareCRLnumber(CRL_Entry* prev, CRL_Entry* curr)
623623
{
624624
int ret = 0;
625-
DECL_MP_INT_SIZE_DYN(prev_num, CRL_MAX_NUM_SZ * CHAR_BIT,
626-
CRL_MAX_NUM_SZ * CHAR_BIT);
627-
DECL_MP_INT_SIZE_DYN(curr_num, CRL_MAX_NUM_SZ * CHAR_BIT,
628-
CRL_MAX_NUM_SZ * CHAR_BIT);
625+
DECL_MP_INT_SIZE_DYN(prev_num, CRL_MAX_NUM_SZ_BITS,
626+
CRL_MAX_NUM_SZ_BITS);
627+
DECL_MP_INT_SIZE_DYN(curr_num, CRL_MAX_NUM_SZ_BITS,
628+
CRL_MAX_NUM_SZ_BITS);
629629

630-
NEW_MP_INT_SIZE(prev_num, CRL_MAX_NUM_SZ * CHAR_BIT, NULL,
630+
NEW_MP_INT_SIZE(prev_num, CRL_MAX_NUM_SZ_BITS, NULL,
631631
DYNAMIC_TYPE_TMP_BUFFER);
632-
NEW_MP_INT_SIZE(curr_num, CRL_MAX_NUM_SZ * CHAR_BIT, NULL,
632+
NEW_MP_INT_SIZE(curr_num, CRL_MAX_NUM_SZ_BITS, NULL,
633633
DYNAMIC_TYPE_TMP_BUFFER);
634634
#ifdef MP_INT_SIZE_CHECK_NULL
635635
if ((prev_num == NULL) || (curr_num == NULL)) {
636636
ret = MEMORY_E;
637637
}
638638
#endif
639639

640-
if (ret == 0 && ((INIT_MP_INT_SIZE(prev_num, CRL_MAX_NUM_SZ * CHAR_BIT)
640+
if (ret == 0 && ((INIT_MP_INT_SIZE(prev_num, CRL_MAX_NUM_SZ_BITS)
641641
!= MP_OKAY) || (INIT_MP_INT_SIZE(curr_num,
642-
CRL_MAX_NUM_SZ * CHAR_BIT)) != MP_OKAY)) {
642+
CRL_MAX_NUM_SZ_BITS)) != MP_OKAY)) {
643643
ret = MP_INIT_E;
644644
}
645645

tests/api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31627,7 +31627,7 @@ static void updateCrlCb(CrlInfo* old, CrlInfo* cnew)
3162731627
AssertIntEQ(crl1Info.nextDateMaxLen, old->nextDateMaxLen);
3162831628
AssertIntEQ(crl1Info.nextDateFormat, old->nextDateFormat);
3162931629
AssertIntEQ(XMEMCMP(
31630-
crl1Info.crlNumber, old->crlNumber, CRL_MAX_NUM_HEX_STR_SZ), 0);
31630+
crl1Info.crlNumber, old->crlNumber, sizeof(old->crlNumber)), 0);
3163131631
AssertIntEQ(XMEMCMP(
3163231632
crl1Info.issuerHash, old->issuerHash, old->issuerHashLen), 0);
3163331633
AssertIntEQ(XMEMCMP(
@@ -31642,7 +31642,7 @@ static void updateCrlCb(CrlInfo* old, CrlInfo* cnew)
3164231642
AssertIntEQ(crlRevInfo.nextDateMaxLen, cnew->nextDateMaxLen);
3164331643
AssertIntEQ(crlRevInfo.nextDateFormat, cnew->nextDateFormat);
3164431644
AssertIntEQ(XMEMCMP(
31645-
crlRevInfo.crlNumber, cnew->crlNumber, CRL_MAX_NUM_HEX_STR_SZ), 0);
31645+
crlRevInfo.crlNumber, cnew->crlNumber, sizeof(cnew->crlNumber)), 0);
3164631646
AssertIntEQ(XMEMCMP(
3164731647
crlRevInfo.issuerHash, cnew->issuerHash, cnew->issuerHashLen), 0);
3164831648
AssertIntEQ(XMEMCMP(

wolfcrypt/src/asn.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40856,22 +40856,13 @@ static int ParseCRL_Extensions(DecodedCRL* dcrl, const byte* buf,
4085640856
ret = BUFFER_E;
4085740857
/* Check CRL number size
4085840858
* if it exceeds CRL_MAX_NUM_SZ(octets)
40859+
* and CRL_MAX_NUM_HEX_STR_SZ(hex string)
4085940860
*/
40860-
if (mp_unsigned_bin_size(m) > CRL_MAX_NUM_SZ) {
40861+
if (((needed = mp_unsigned_bin_size(m)) > CRL_MAX_NUM_SZ) ||
40862+
((needed * 2 + 1) > CRL_MAX_NUM_HEX_STR_SZ)) {
4086140863
WOLFSSL_MSG("CRL number exceeds limitation.");
4086240864
ret = BUFFER_E;
4086340865
}
40864-
/* Determine required size for hexadecimal string encoding */
40865-
if (ret == MP_OKAY &&
40866-
(mp_radix_size(m, MP_RADIX_HEX, &needed) != MP_OKAY)) {
40867-
WOLFSSL_MSG("mp_radix_size failure");
40868-
ret = BUFFER_E;
40869-
}
40870-
if (ret == MP_OKAY && needed > CRL_MAX_NUM_HEX_STR_SZ) {
40871-
WOLFSSL_MSG("CRL number hex string"
40872-
" exceeds buffer limitation");
40873-
ret = BUFFER_E;
40874-
}
4087540866
if (ret == MP_OKAY && mp_toradix(m, (char*)dcrl->crlNumber,
4087640867
MP_RADIX_HEX) != MP_OKAY)
4087740868
ret = BUFFER_E;
@@ -40991,22 +40982,13 @@ static int ParseCRL_Extensions(DecodedCRL* dcrl, const byte* buf, word32 idx,
4099140982
}
4099240983
/* Check CRL number size
4099340984
* if it exceeds CRL_MAX_NUM_SZ(octets)
40985+
* and CRL_MAX_NUM_HEX_STR_SZ(hex string)
4099440986
*/
40995-
if (mp_unsigned_bin_size(m) > CRL_MAX_NUM_SZ) {
40987+
if (((needed = mp_unsigned_bin_size(m)) > CRL_MAX_NUM_SZ) ||
40988+
((needed * 2 + 1) > CRL_MAX_NUM_HEX_STR_SZ)) {
4099640989
WOLFSSL_MSG("CRL number exceeds limitation.");
4099740990
ret = BUFFER_E;
4099840991
}
40999-
/* Determine required size for hexadecimal string encoding */
41000-
if (ret == MP_OKAY &&
41001-
(mp_radix_size(m, MP_RADIX_HEX, &needed) != MP_OKAY)) {
41002-
WOLFSSL_MSG("mp_radix_size failure");
41003-
ret = BUFFER_E;
41004-
}
41005-
if (ret == MP_OKAY && needed > CRL_MAX_NUM_HEX_STR_SZ) {
41006-
WOLFSSL_MSG("CRL number hex string"
41007-
" exceeds buffer limitation");
41008-
ret = BUFFER_E;
41009-
}
4101040992
if (ret == 0 && mp_toradix(m, (char*)dcrl->crlNumber,
4101140993
MP_RADIX_HEX) != MP_OKAY)
4101240994
ret = BUFFER_E;

wolfssl/ssl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3795,7 +3795,7 @@ typedef int (*CbCrlIO)(WOLFSSL_CRL* crl, const char* url, int urlSz);
37953795

37963796
#ifdef HAVE_CRL_UPDATE_CB
37973797
typedef struct CrlInfo {
3798-
byte crlNumber[CRL_MAX_NUM_HEX_STR_SZ];
3798+
char crlNumber[CRL_MAX_NUM_HEX_STR_SZ];
37993799
byte *issuerHash;
38003800
word32 issuerHashLen;
38013801
byte *lastDate;

wolfssl/wolfcrypt/asn.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,7 @@ struct RevokedCert {
26942694
#endif /* octets long */
26952695

26962696
#define CRL_MAX_NUM_HEX_STR_SZ (CRL_MAX_NUM_SZ * 2 + 1)
2697+
#define CRL_MAX_NUM_SZ_BITS (CRL_MAX_NUM_SZ * CHAR_BIT)
26972698

26982699
typedef struct DecodedCRL DecodedCRL;
26992700

@@ -2707,7 +2708,7 @@ struct DecodedCRL {
27072708
word32 sigParamsLength; /* length of signature parameters */
27082709
#endif
27092710
byte* signature; /* pointer into raw source, not owned */
2710-
byte crlNumber[CRL_MAX_NUM_HEX_STR_SZ]; /* CRL number extension */
2711+
char crlNumber[CRL_MAX_NUM_HEX_STR_SZ]; /* CRL number extension */
27112712
byte issuerHash[SIGNER_DIGEST_SIZE]; /* issuer name hash */
27122713
byte crlHash[SIGNER_DIGEST_SIZE]; /* raw crl data hash */
27132714
byte lastDate[MAX_DATE_SIZE]; /* last date updated */

0 commit comments

Comments
 (0)