Skip to content

Commit 5bbf967

Browse files
committed
add length validation for Lock-Token to prevent underflow
1 parent 7de11e5 commit 5bbf967

2 files changed

Lines changed: 27 additions & 11 deletions

File tree

modules/ssl/ssl_engine_pphrase.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,13 @@ apr_status_t ssl_load_encrypted_pkey(server_rec *s, apr_pool_t *p, int idx,
179179
* are used to give a better idea as to what failed.
180180
*/
181181
if (pkey_mtime) {
182-
ssl_asn1_t *asn1 = ssl_asn1_table_get(mc->retained->privkeys, key_id);
183-
if (asn1 && (asn1->source_mtime == pkey_mtime)) {
184-
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, APLOGNO(02575)
185-
"Reusing existing private key from %s on restart",
186-
ppcb_arg.pkey_file);
187-
return APR_SUCCESS;
188-
}
182+
ssl_asn1_t *asn1 = ssl_asn1_table_get(mc->retained->privkeys, key_id);
183+
if (asn1 && (asn1->source_mtime == pkey_mtime)) {
184+
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, APLOGNO(02575)
185+
"Reusing existing private key from %s on restart",
186+
ppcb_arg.pkey_file);
187+
return APR_SUCCESS;
188+
}
189189
}
190190

191191
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, APLOGNO(02576)
@@ -338,6 +338,11 @@ apr_status_t ssl_load_encrypted_pkey(server_rec *s, apr_pool_t *p, int idx,
338338
/* Cache the private key in the global module configuration so it
339339
* can be used after subsequent reloads. */
340340
asn1 = ssl_asn1_table_set(mc->retained->privkeys, key_id, pPrivateKey);
341+
if (!asn1) {
342+
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s,
343+
"mod_ssl: Failed to cache private key");
344+
return ssl_die(s);
345+
}
341346

342347
if (ppcb_arg.nPassPhraseDialogCur != 0) {
343348
/* remember mtime of encrypted keys */
@@ -1024,4 +1029,4 @@ apr_status_t modssl_load_engine_keypair(server_rec *s,
10241029
vhostid, certid ? certid : "no cert", keyid);
10251030
return APR_ENOTIMPL;
10261031
#endif
1027-
}
1032+
}

modules/ssl/ssl_util.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,14 @@ ssl_asn1_t *ssl_asn1_table_set(apr_hash_t *table, const char *key,
201201
{
202202
apr_ssize_t klen = strlen(key);
203203
ssl_asn1_t *asn1 = apr_hash_get(table, key, klen);
204-
apr_size_t length = i2d_PrivateKey(pkey, NULL);
204+
int derlen = i2d_PrivateKey(pkey, NULL);
205+
if (derlen <= 0) {
206+
ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
207+
"mod_ssl: Failed to encode private key");
208+
return NULL;
209+
}
210+
211+
apr_size_t length = (apr_size_t)derlen;
205212
unsigned char *p;
206213

207214
/* Re-use structure if cached previously. */
@@ -220,7 +227,11 @@ ssl_asn1_t *ssl_asn1_table_set(apr_hash_t *table, const char *key,
220227

221228
asn1->nData = length;
222229
p = asn1->cpData;
223-
i2d_PrivateKey(pkey, &p); /* increases p by length */
230+
if (i2d_PrivateKey(pkey, &p) != derlen) {
231+
ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
232+
"mod_ssl: Failed to serialize private key");
233+
return NULL;
234+
}
224235

225236
return asn1;
226237
}
@@ -506,4 +517,4 @@ int modssl_is_engine_id(const char *name)
506517
#else
507518
return 0;
508519
#endif
509-
}
520+
}

0 commit comments

Comments
 (0)