Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit b4f4ae9

Browse files
committed
add check for null dereference in SSL serf fetcher
SSL_set_tlsext_host_name did an unchecked dereference of context->ssl which could be null. Check for null and log on this case.
1 parent a49af6b commit b4f4ae9

4 files changed

Lines changed: 104 additions & 7 deletions

File tree

‎.gitignore‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Makefile
2+
*.mk
3+
*.Makefile
4+
out/*
5+
testing/*
6+
build/android/*
7+
build/mac/*
8+
build/linux/*
9+
build/internal/*
10+
build/win/*
11+
build/ios/*
12+
build/gyp_helper.pyc
13+
build/landmine_utils.pyc
14+
build/temp_gyp/*
15+
gclient.timestamp
16+
third_party/apr/src/*
17+
third_party/aprutil/src/*
18+
third_party/boringssl/*
19+
third_party/chromium/src/base/*
20+
third_party/chromium/src/build/*
21+
third_party/chromium/src/net/base/*
22+
third_party/chromium/src/url/*
23+
third_party/chromium_deps/*
24+
third_party/closure_library/*
25+
third_party/domain_registry_provider/*
26+
third_party/gflags/src/*
27+
third_party/giflib/*
28+
third_party/google-sparsehash/src/*
29+
third_party/httpd/src/*
30+
third_party/httpd24/src/*
31+
third_party/icu/*
32+
third_party/jsoncpp/src/*
33+
third_party/libjpeg_turbo/src/*
34+
third_party/libjpeg_turbo/yasm/*
35+
third_party/libwebp/*
36+
third_party/mod_spdy/*
37+
third_party/modp_b64/*
38+
third_party/optipng/*
39+
third_party/pagespeed*
40+
third_party/protobuf/*
41+
third_party/re2/src/*
42+
third_party/serf/src/*
43+
third_party/zlib/*
44+
tools/*
45+
third_party/domain_registry_provider
46+
third_party/domain_registry_provider/*

‎net/instaweb/system/serf_url_async_fetcher.cc‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,12 @@ class SerfFetch : public PoolElement<SerfFetch> {
330330
SSLCertError, SSLCertChainError,
331331
fetch);
332332

333-
serf_ssl_set_hostname(fetch->ssl_context_, fetch->sni_host_);
333+
status = serf_ssl_set_hostname(fetch->ssl_context_, fetch->sni_host_);
334+
if (status != APR_SUCCESS) {
335+
LOG(INFO) << "Unable to set hostname from serf fetcher. Connection "
336+
"setup failed";
337+
return status;
338+
}
334339
*write_bkt = serf_bucket_ssl_encrypt_create(*write_bkt,
335340
fetch->ssl_context_,
336341
fetch->bucket_alloc_);

‎third_party/serf/instaweb_ssl_buckets.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,9 @@ apr_status_t serf_ssl_set_hostname(serf_ssl_context_t *context,
12121212
const char * hostname)
12131213
{
12141214
#ifdef SSL_set_tlsext_host_name
1215-
if (SSL_set_tlsext_host_name(context->ssl, hostname) != 1) {
1215+
if (!context->ssl) {
1216+
return APR_EGENERAL;
1217+
} else if (SSL_set_tlsext_host_name(context->ssl, hostname) != 1) {
12161218
ERR_clear_error();
12171219
}
12181220
#endif

‎third_party/serf/serf.diff‎

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@
267267
+ return serf_request_bucket_request_create_for_host(
268268
+ request, method, uri, body, allocator, NULL);
269269
+}
270-
--- serf/src/buckets/ssl_buckets.c 2012-08-29 13:52:29.443913000 -0400
271-
+++ src/third_party/serf/instaweb_ssl_buckets.c 2013-05-14 09:56:37.292605000 -0400
270+
--- serf/src/buckets/ssl_buckets.c 2012-08-29 13:29:42.000000000 -0400
271+
+++ src/third_party/serf/instaweb_ssl_buckets.c 2015-07-27 10:56:12.000000000 -0400
272272
@@ -34,6 +34,11 @@
273273
* Originally developed by Aaron Bannert and Justin Erenkrantz, eBuilt.
274274
*/
@@ -281,7 +281,40 @@
281281
#include <apr_pools.h>
282282
#include <apr_network_io.h>
283283
#include <apr_portable.h>
284-
@@ -1160,7 +1165,9 @@
284+
@@ -873,7 +878,9 @@
285+
#if APR_HAS_THREADS
286+
int i, numlocks;
287+
#endif
288+
+#ifndef OPENSSL_IS_BORINGSSL
289+
CRYPTO_malloc_init();
290+
+#endif
291+
ERR_load_crypto_strings();
292+
SSL_load_error_strings();
293+
SSL_library_init();
294+
@@ -971,8 +978,13 @@
295+
else {
296+
int err = ERR_get_error();
297+
ERR_clear_error();
298+
+#ifndef OPENSSL_IS_BORINGSSL
299+
if (ERR_GET_LIB(err) == ERR_LIB_PKCS12 &&
300+
ERR_GET_REASON(err) == PKCS12_R_MAC_VERIFY_FAILURE) {
301+
+#else
302+
+ if (ERR_GET_LIB(err) == ERR_LIB_PKCS8 &&
303+
+ ERR_GET_REASON(err) == PKCS8_R_INCORRECT_PASSWORD) {
304+
+#endif
305+
if (ctx->cert_pw_callback) {
306+
const char *password;
307+
308+
@@ -1102,6 +1114,8 @@
309+
ssl_ctx->allocator = allocator;
310+
311+
ssl_ctx->ctx = SSL_CTX_new(SSLv23_client_method());
312+
+ /* Use the best possible protocol version, but disable the broken SSLv2/3 */
313+
+ SSL_CTX_set_options(ssl_ctx->ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
314+
315+
SSL_CTX_set_client_cert_cb(ssl_ctx->ctx, ssl_need_client_cert);
316+
ssl_ctx->cached_cert = 0;
317+
@@ -1160,7 +1174,9 @@
285318

286319
/* SSL_free implicitly frees the underlying BIO. */
287320
SSL_free(ssl_ctx->ssl);
@@ -291,7 +324,18 @@
291324

292325
p = ssl_ctx->pool;
293326

294-
@@ -1209,6 +1216,28 @@
327+
@@ -1193,7 +1209,9 @@
328+
const char * hostname)
329+
{
330+
#ifdef SSL_set_tlsext_host_name
331+
- if (SSL_set_tlsext_host_name(context->ssl, hostname) != 1) {
332+
+ if (!context->ssl) {
333+
+ return APR_EGENERAL;
334+
+ } else if (SSL_set_tlsext_host_name(context->ssl, hostname) != 1) {
335+
ERR_clear_error();
336+
}
337+
#endif
338+
@@ -1209,6 +1227,28 @@
295339
return result ? APR_SUCCESS : APR_EGENERAL;
296340
}
297341

@@ -320,7 +364,7 @@
320364
apr_status_t serf_ssl_load_cert_file(
321365
serf_ssl_certificate_t **cert,
322366
const char *file_path,
323-
@@ -1527,6 +1556,7 @@
367+
@@ -1527,6 +1567,7 @@
324368

325369
if (!--ctx->ssl_ctx->refcount) {
326370
ssl_free_context(ctx->ssl_ctx);

0 commit comments

Comments
 (0)