Skip to content

Commit b803b0f

Browse files
committed
Improve performance for the rare case of handling large OCSP responses.
1 parent 8b80c08 commit b803b0f

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

native/src/sslutils.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -866,19 +866,19 @@ static OCSP_RESPONSE *parse_ocsp_resp(char *buf, int len)
866866

867867
/* Reads the response from the APR socket to a buffer, and parses the buffer to
868868
return the OCSP response */
869-
#define ADDLEN 512
869+
#define BUFFER_SIZE 512
870870
static OCSP_RESPONSE *ocsp_get_resp(apr_pool_t *mp, apr_socket_t *sock)
871871
{
872872
int buflen;
873873
apr_size_t totalread = 0;
874874
apr_size_t readlen;
875-
char *buf, tmpbuf[ADDLEN];
875+
char *buf, tmpbuf[BUFFER_SIZE];
876876
apr_status_t rv = APR_SUCCESS;
877877
apr_pool_t *p;
878878
OCSP_RESPONSE *resp;
879879

880880
apr_pool_create(&p, mp);
881-
buflen = ADDLEN;
881+
buflen = BUFFER_SIZE;
882882
buf = apr_palloc(p, buflen);
883883
if (buf == NULL) {
884884
apr_pool_destroy(p);
@@ -890,12 +890,12 @@ static OCSP_RESPONSE *ocsp_get_resp(apr_pool_t *mp, apr_socket_t *sock)
890890
rv = apr_socket_recv(sock, tmpbuf, &readlen);
891891
if (rv == APR_SUCCESS) { /* if we have read something .. we can put it in the buffer*/
892892
if ((totalread + readlen) >= buflen) {
893-
buf = apr_xrealloc(buf, buflen, buflen + ADDLEN, p);
893+
buf = apr_xrealloc(buf, buflen, buflen * 2, p);
894894
if (buf == NULL) {
895895
apr_pool_destroy(p);
896896
return NULL;
897897
}
898-
buflen += ADDLEN; /* if needed we enlarge the buffer */
898+
buflen *= 2; /* if needed we enlarge the buffer */
899899
}
900900
memcpy(buf + totalread, tmpbuf, readlen); /* the copy to the buffer */
901901
totalread += readlen; /* update the total bytes read */

xdocs/miscellaneous/changelog.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
OCSP verification being enabled by default when the expected behaviour was
5959
disabled by default. (markt)
6060
</fix>
61+
<scode>
62+
Improve performance for the rare case of handling large OCSP responses.
63+
(markt)
64+
</scode>
6165
</changelog>
6266
</section>
6367
<section name="2.0.12" rtext="2026-01-12">

0 commit comments

Comments
 (0)