Skip to content

Commit 6bb122d

Browse files
committed
Address copilot review
1 parent 6fc83e2 commit 6bb122d

4 files changed

Lines changed: 23 additions & 14 deletions

File tree

examples/ocsp_responder/ocsp_responder.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,12 @@ static int PopulateResponderFromIndex(OcspResponder* responder, IndexEntry* inde
444444
}
445445

446446
for (i = 0; i < serialLen; i++) {
447-
int high = (p[i*2] >= 'A') ? (p[i*2] - 'A' + 10) :
448-
(p[i*2] >= 'a') ? (p[i*2] - 'a' + 10) : (p[i*2] - '0');
449-
int low = (p[i*2+1] >= 'A') ? (p[i*2+1] - 'A' + 10) :
450-
(p[i*2+1] >= 'a') ? (p[i*2+1] - 'a' + 10) : (p[i*2+1] - '0');
447+
int high = ('0' <= p[i*2] && p[i*2] <= '9') ? (p[i*2] - '0') :
448+
('A' <= p[i*2] && p[i*2] <= 'F') ? (p[i*2] - 'A' + 10) :
449+
(p[i*2] - 'a' + 10);
450+
int low = ('0' <= p[i*2+1] && p[i*2+1] <= '9') ? (p[i*2+1] - '0') :
451+
('A' <= p[i*2+1] && p[i*2+1] <= 'F') ? (p[i*2+1] - 'A' + 10) :
452+
(p[i*2+1] - 'a' + 10);
451453
serial[i] = (byte)((high << 4) | low);
452454
}
453455

@@ -834,7 +836,6 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
834836
}
835837
(void)wc_GetDecodedCertSubject(&caCert, NULL, &caSubjectSz);
836838
(void)caSubjectSz; /* Not used in current implementation */
837-
(void)caSubjectSz; /* Not used in current implementation */
838839

839840
/* Load index file if provided */
840841
if (opts.indexFile) {

scripts/ocsp-stapling-with-wolfssl-responder.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ wait_for_readyFile(){
171171

172172
counter=0
173173

174-
while [ ! -s $1 -a "$counter" -lt 20 ]; do
174+
while [ ! -s "$1" ] && [ "$counter" -lt 20 ]; do
175175
if [[ -n "${2-}" ]]; then
176-
if ! kill -0 $2 2>&-; then
176+
if ! kill -0 "$2" 2>&-; then
177177
echo "pid $2 for port ${3-} exited before creating ready file. bailing..."
178178
exit 1
179179
fi
@@ -183,7 +183,7 @@ wait_for_readyFile(){
183183
counter=$((counter+ 1))
184184
done
185185

186-
if test -e $1; then
186+
if test -e "$1"; then
187187
echo -e "found ready file, starting client..."
188188
else
189189
echo -e "NO ready file at $1 -- ending test..."

src/ocsp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ static int CheckOcspResponderChain(OcspEntry* single, byte* issuerHash,
636636
* @param bs The basic OCSP response to verify
637637
* @param subjectHash The subject key hash of the OCSP responder certificate
638638
* @param extExtKeyUsage The extended key usage bits of the responder certificate
639-
* @param issuerHash The issuer key hash of the OCSP responder certificate
639+
* @param issuerHash The issuer name hash of the OCSP responder certificate
640640
* @param vp Unused (reserved for future use)
641641
* @return 1 if the responder is authorized to sign the response, 0 otherwise
642642
*/

wolfcrypt/src/asn.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ static word32 SizeASNLength(word32 length)
549549
* @param [in] heap Dynamic memory allocation hint.
550550
*/
551551
#define ALLOC_ASNGETDATA(name, cnt, err, heap) \
552-
(void)(cnt); (void)(err); (void)(heap); WC_DO_NOTHING
552+
do { (void)(cnt); (void)(err); (void)(heap); } while (0)
553553

554554
/* Clears the memory of the dynamic BER encoding data.
555555
*
@@ -567,7 +567,7 @@ static word32 SizeASNLength(word32 length)
567567
* @param [in] heap Dynamic memory allocation hint.
568568
*/
569569
#define FREE_ASNGETDATA(name, heap) \
570-
(void)(name); (void)(heap); WC_DO_NOTHING
570+
do { (void)(name); (void)(heap); } while (0)
571571

572572
/* Declare the variable that is the dynamic data for encoding DER data.
573573
*
@@ -585,7 +585,7 @@ static word32 SizeASNLength(word32 length)
585585
* @param [in] heap Dynamic memory allocation hint.
586586
*/
587587
#define ALLOC_ASNSETDATA(name, cnt, err, heap) \
588-
(void)(cnt); (void)(err); (void)(heap); WC_DO_NOTHING
588+
do { (void)(cnt); (void)(err); (void)(heap); } while (0)
589589

590590
/* Clears the memory of the dynamic BER encoding data.
591591
*
@@ -603,7 +603,7 @@ static word32 SizeASNLength(word32 length)
603603
* @param [in] heap Dynamic memory allocation hint.
604604
*/
605605
#define FREE_ASNSETDATA(name, heap) \
606-
(void)(name); (void)(heap); WC_DO_NOTHING
606+
do { (void)(name); (void)(heap); } while (0)
607607
#endif
608608

609609

@@ -41385,6 +41385,8 @@ int EncodeOcspRequest(OcspRequest* req, byte* output, word32 size)
4138541385

4138641386
algoSz = SetAlgoID(req->hashAlg, algoArray, oidHashType, 0);
4138741387
keyIdSz = wc_HashGetDigestSize(wc_OidGetHash(req->hashAlg));
41388+
if (keyIdSz <= 0 || keyIdSz > WC_MAX_DIGEST_SIZE)
41389+
return BAD_FUNC_ARG;
4138841390

4138941391
issuerSz = SetDigest(req->issuerHash, keyIdSz, issuerArray);
4139041392
issuerKeySz = SetDigest(req->issuerKeyHash, keyIdSz, issuerKeyArray);
@@ -41451,11 +41453,17 @@ int EncodeOcspRequest(OcspRequest* req, byte* output, word32 size)
4145141453

4145241454
CALLOC_ASNSETDATA(dataASN, ocspRequestASN_Length, ret, req->heap);
4145341455

41456+
if (ret == 0) {
41457+
int digestSz = wc_HashGetDigestSize(wc_OidGetHash(req->hashAlg));
41458+
if (digestSz <= 0)
41459+
ret = BAD_FUNC_ARG;
41460+
else
41461+
keyIdSz = (word32)digestSz;
41462+
}
4145441463
if (ret == 0) {
4145541464
/* Set OID of hash algorithm use on issuer and key. */
4145641465
SetASN_OID(&dataASN[OCSPREQUESTASN_IDX_TBS_REQ_HASH_OID], req->hashAlg,
4145741466
oidHashType);
41458-
keyIdSz = (word32)wc_HashGetDigestSize(wc_OidGetHash(req->hashAlg));
4145941467
/* Set issuer, issuer key hash and serial number of certificate being
4146041468
* checked. */
4146141469
SetASN_Buffer(&dataASN[OCSPREQUESTASN_IDX_TBS_REQ_ISSUER],

0 commit comments

Comments
 (0)