Skip to content

Commit e9a5c75

Browse files
committed
Address review feedback
- LoadFile now validates fread read the full file size and returns NULL on short read. - ocsp-responder-http checks wolfSSL_Init return value. - Remove bare scope block around sigaction setup.
1 parent b79c987 commit e9a5c75

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

ocsp/responder/ocsp-load-certs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static WC_MAYBE_UNUSED byte* LoadFile(const char* path, int* outSz)
4646
if (!buf) { fclose(f); return NULL; }
4747
*outSz = (int)fread(buf, 1, (size_t)sz, f);
4848
fclose(f);
49+
if (*outSz != (int)sz) { free(buf); return NULL; }
4950
return buf;
5051
}
5152

ocsp/responder/ocsp-responder-http.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ int main(int argc, char** argv)
237237
word32 caSubjectSz = sizeof(caSubject);
238238
int sockfd = -1, clientfd, opt = 1, i, ret = 0;
239239
struct sockaddr_in addr;
240+
struct sigaction sa;
240241

241242
if (argc < 4) {
242243
printf("Usage: %s <port> <ca-cert> <ca-key> [good-cert ...]\n\n"
@@ -252,20 +253,21 @@ int main(int argc, char** argv)
252253
certFile = argv[2];
253254
keyFile = argv[3];
254255

255-
wolfSSL_Init();
256-
{
257-
struct sigaction sa;
258-
sa.sa_handler = sigHandler;
259-
sa.sa_flags = 0; /* No SA_RESTART so accept() returns on signal */
260-
sigemptyset(&sa.sa_mask);
261-
sigaction(SIGINT, &sa, NULL);
262-
sigaction(SIGTERM, &sa, NULL);
263-
264-
/* Ignore SIGPIPE so client disconnections during writes don't crash */
265-
sa.sa_handler = SIG_IGN;
266-
sigaction(SIGPIPE, &sa, NULL);
256+
if (wolfSSL_Init() != WOLFSSL_SUCCESS) {
257+
fprintf(stderr, "wolfSSL_Init failed\n");
258+
return 1;
267259
}
268260

261+
sa.sa_handler = sigHandler;
262+
sa.sa_flags = 0; /* No SA_RESTART so accept() returns on signal */
263+
sigemptyset(&sa.sa_mask);
264+
sigaction(SIGINT, &sa, NULL);
265+
sigaction(SIGTERM, &sa, NULL);
266+
267+
/* Ignore SIGPIPE so client disconnections during writes don't crash */
268+
sa.sa_handler = SIG_IGN;
269+
sigaction(SIGPIPE, &sa, NULL);
270+
269271
caCertDer = LoadCertDer(certFile, &caCertDerSz);
270272
caKeyDer = LoadKeyDer(keyFile, &caKeyDerSz);
271273
if (!caCertDer || !caKeyDer) {

0 commit comments

Comments
 (0)