Skip to content

Commit 3c8a9a6

Browse files
committed
mod_ssl uses free() inappropriately in several places, to free
memory which has been previously allocated inside OpenSSL. Such memory should be freed with OPENSSL_free(), not with free(). Submitted by: Nadav Har'El <nyh@math.technion.ac.il>, Madhusudan Mathihalli <madhusudan_mathihalli@hp.com> Reviewed by: Jeff Trawick git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@97307 13f79535-47bb-0310-9956-ffa450edef68
1 parent 9392cc9 commit 3c8a9a6

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Changes with Apache 2.0.44
22

3+
*) mod_ssl uses free() inappropriately in several places, to free
4+
memory which has been previously allocated inside OpenSSL.
5+
Such memory should be freed with OPENSSL_free(), not with free().
6+
[Nadav Har'El <nyh@math.technion.ac.il>,
7+
Madhusudan Mathihalli <madhusudan_mathihalli@hp.com>].
8+
39
*) Emit a message to the error log when we return 404 because
410
the URI contained '%2f'. (This was previously nastily silent
511
and difficult to debug.) [Ken Coar]

modules/ssl/ssl_engine_kernel.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ int ssl_hook_UserCheck(request_rec *r)
968968
X509_NAME *name = X509_get_subject_name(sslconn->client_cert);
969969
char *cp = X509_NAME_oneline(name, NULL, 0);
970970
sslconn->client_dn = apr_pstrdup(r->connection->pool, cp);
971-
free(cp);
971+
modssl_free(cp);
972972
}
973973

974974
clientdn = (char *)sslconn->client_dn;
@@ -1299,11 +1299,11 @@ int ssl_callback_SSLVerify(int ok, X509_STORE_CTX *ctx)
12991299
iname ? iname : "-unknown-");
13001300

13011301
if (sname) {
1302-
free(sname);
1302+
modssl_free(sname);
13031303
}
13041304

13051305
if (iname) {
1306-
free(iname);
1306+
modssl_free(iname);
13071307
}
13081308
}
13091309

@@ -1555,7 +1555,7 @@ int ssl_callback_SSLVerify_CRL(int ok, X509_STORE_CTX *ctx, conn_rec *c)
15551555
"Certificate with serial %ld (0x%lX) "
15561556
"revoked per CRL from issuer %s",
15571557
serial, serial, cp);
1558-
free(cp);
1558+
modssl_free(cp);
15591559
}
15601560

15611561
X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_REVOKED);
@@ -1593,6 +1593,7 @@ static void modssl_proxy_info_log(server_rec *s,
15931593
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
15941594
SSLPROXY_CERT_CB_LOG_FMT "%s, sending %s",
15951595
sc->vhost_id, msg, dn ? dn : "-uknown-");
1596+
modssl_free(dn);
15961597
}
15971598

15981599
/*

modules/ssl/ssl_engine_vars.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ static char *ssl_var_lookup_ssl_cert(apr_pool_t *p, X509 *xs, char *var)
334334
xsname = X509_get_subject_name(xs);
335335
cp = X509_NAME_oneline(xsname, NULL, 0);
336336
result = apr_pstrdup(p, cp);
337-
free(cp);
337+
modssl_free(cp);
338338
resdup = FALSE;
339339
}
340340
else if (strlen(var) > 5 && strcEQn(var, "S_DN_", 5)) {
@@ -346,7 +346,7 @@ static char *ssl_var_lookup_ssl_cert(apr_pool_t *p, X509 *xs, char *var)
346346
xsname = X509_get_issuer_name(xs);
347347
cp = X509_NAME_oneline(xsname, NULL, 0);
348348
result = apr_pstrdup(p, cp);
349-
free(cp);
349+
modssl_free(cp);
350350
resdup = FALSE;
351351
}
352352
else if (strlen(var) > 5 && strcEQn(var, "I_DN_", 5)) {

modules/ssl/ssl_toolkit_compat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@
105105

106106
#define modssl_set_cipher_list SSL_set_cipher_list
107107

108+
#define modssl_free OPENSSL_free
109+
108110
#define EVP_PKEY_reference_inc(pkey) \
109111
CRYPTO_add(&((pkey)->references), +1, CRYPTO_LOCK_X509_PKEY)
110112

@@ -148,6 +150,8 @@
148150
#define modssl_set_cipher_list(ssl, l) \
149151
SSL_set_cipher_list(ssl, (char *)l)
150152

153+
#define modssl_free free
154+
151155
#ifndef PEM_F_DEF_CALLBACK
152156
#define PEM_F_DEF_CALLBACK PEM_F_DEF_CB
153157
#endif

0 commit comments

Comments
 (0)