Skip to content

Commit 29298d6

Browse files
committed
Address code review
1 parent e0390b6 commit 29298d6

4 files changed

Lines changed: 16 additions & 22 deletions

File tree

src/ocsp/clu_ocsp.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* clu_ocsp.c
22
*
3-
* Copyright (C) 2006-2025 wolfSSL Inc.
3+
* Copyright (C) 2006-2026 wolfSSL Inc.
44
*
55
* This file is part of wolfSSL.
66
*
@@ -511,10 +511,11 @@ static byte respBuffer[16384];
511511
#ifndef _WIN32
512512
#include <signal.h>
513513
#include <errno.h>
514+
static volatile sig_atomic_t shutdownRequested = 0;
515+
#else
516+
static volatile int shutdownRequested = 0;
514517
#endif
515518

516-
static volatile sig_atomic_t shutdownRequested = 0;
517-
518519
#ifndef _WIN32
519520
/* Signal handler for SIGINT and SIGTERM - sets shutdown flag */
520521
static void ocspSignalHandler(int sig)
@@ -752,27 +753,18 @@ static int ocspResponder(OcspResponderConfig* config)
752753
if (indexEntries != NULL) {
753754
IndexEntry* entry;
754755
for (entry = indexEntries; entry != NULL; entry = entry->next) {
755-
byte serial[64];
756+
byte* serial = NULL;
756757
word32 serialLen = 0;
757758
enum Ocsp_Cert_Status status;
758759
time_t revTime = 0;
759-
word32 i;
760-
char* p = entry->serial;
761760

762761
/* Convert hex string to bytes */
763-
serialLen = (word32)XSTRLEN(entry->serial) / 2;
764-
if (serialLen == 0 || serialLen > sizeof(serial)) {
762+
if (wolfCLU_hexToBin(entry->serial, &serial, &serialLen,
763+
NULL, NULL, NULL, NULL, NULL, NULL,
764+
NULL, NULL, NULL) != WOLFCLU_SUCCESS) {
765765
continue;
766766
}
767767

768-
for (i = 0; i < serialLen; i++) {
769-
int high = (p[i*2] >= 'A') ? (p[i*2] - 'A' + 10) :
770-
(p[i*2] >= 'a') ? (p[i*2] - 'a' + 10) : (p[i*2] - '0');
771-
int low = (p[i*2+1] >= 'A') ? (p[i*2+1] - 'A' + 10) :
772-
(p[i*2+1] >= 'a') ? (p[i*2+1] - 'a' + 10) : (p[i*2+1] - '0');
773-
serial[i] = (byte)((high << 4) | low);
774-
}
775-
776768
/* Determine status */
777769
if (entry->status == 'V') {
778770
status = CERT_GOOD;
@@ -790,6 +782,7 @@ static int ocspResponder(OcspResponderConfig* config)
790782
serial, serialLen, status, revTime,
791783
CRL_REASON_UNSPECIFIED,
792784
(status == CERT_GOOD) ? 86400 : 0);
785+
wolfCLU_freeBins(serial, NULL, NULL, NULL, NULL);
793786
}
794787
}
795788

@@ -868,6 +861,9 @@ static int ocspResponder(OcspResponderConfig* config)
868861
if (transportSendResponse(clientfd, transportType, respBuffer, (int)respSz) != 0)
869862
goto continue_loop;
870863

864+
/* Only count successfully processed requests toward the -nrequest
865+
* limit. Failed reads/sends jump to continue_loop above, so a
866+
* misbehaving client cannot exhaust the budget. */
871867
requestsProcessed++;
872868

873869
/* Check if we've hit the request limit */

src/tools/clu_http.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ int wolfCLU_HttpServerSendError(SOCKET_T clientfd, int statusCode,
379379
return -1;
380380
}
381381

382-
return (send(clientfd, response, (size_t)len, 0) == len) ? 0 : -1;
382+
return (wolfCLU_SendAll(clientfd, response, len) == len) ? 0 : -1;
383383
}
384384

385385
/**
@@ -434,7 +434,7 @@ int wolfCLU_HttpServerParseRequest(const byte* httpReq, int httpReqSz,
434434
}
435435

436436
/* Find body (has to appear after headers) */
437-
bodyStart = XSTRSTR((char*)contentLen, "\r\n\r\n");
437+
bodyStart = XSTRSTR(contentLen != NULL ? contentLen : (char*)httpReq, "\r\n\r\n");
438438
if (!bodyStart)
439439
return -1;
440440
bodyAvail = (int)(((char*)httpReq + httpReqSz) -

tests/ocsp-scgi/include.am

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
# Tests will be skipped if nginx or openssl are not available
77
dist_noinst_SCRIPTS += tests/ocsp-scgi/ocsp-scgi-test.sh
88

9-
EXTRA_DIST += \
10-
tests/ocsp-scgi/scgi_params \
11-
tests/ocsp-scgi/README.md
9+
EXTRA_DIST += tests/ocsp-scgi/scgi_params

wolfclu/clu_header_main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ int wolfCLU_HttpServerParseRequest(const byte* httpReq, int httpReqSz,
738738
* @param sockfd socket descriptor
739739
* @param buffer buffer to store the complete request
740740
* @param bufferSz size of buffer
741-
* @param req output structure to store parsed request (defined in clu_scgi.h)
741+
* @param req output structure to store parsed request
742742
* @return 0 on success, negative on error
743743
*/
744744
struct ScgiRequest {

0 commit comments

Comments
 (0)