forked from XNovathor/android_device_sony_montblanc-common
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
From eb6a8fdfebf0cf4872394e1501103c2519b53a1c Mon Sep 17 00:00:00 2001 | ||
From: "Dr. Stephen Henson" <steve@openssl.org> | ||
Date: Sat, 12 Apr 2014 20:19:06 +0530 | ||
Subject: [PATCH] openssl: Add heartbeat extension bounds check | ||
|
||
Change-Id: I86b9adab4dea2b57fdc8e5f4c78afa27d74b9de3 | ||
--- | ||
ssl/d1_both.c | 26 ++++++++++++++++++-------- | ||
ssl/t1_lib.c | 14 +++++++++----- | ||
2 files changed, 27 insertions(+), 13 deletions(-) | ||
|
||
diff --git a/external/openssl/ssl/d1_both.c b/external/openssl/ssl/d1_both.c | ||
index de8bab8..436ab67 100644 | ||
--- a/external/openssl/ssl/d1_both.c | ||
+++ b/external/openssl/ssl/d1_both.c | ||
@@ -1452,26 +1452,36 @@ dtls1_process_heartbeat(SSL *s) | ||
unsigned int payload; | ||
unsigned int padding = 16; /* Use minimum padding */ | ||
|
||
- /* Read type and payload length first */ | ||
- hbtype = *p++; | ||
- n2s(p, payload); | ||
- pl = p; | ||
- | ||
if (s->msg_callback) | ||
s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT, | ||
&s->s3->rrec.data[0], s->s3->rrec.length, | ||
s, s->msg_callback_arg); | ||
|
||
+ /* Read type and payload length first */ | ||
+ if (1 + 2 + 16 > s->s3->rrec.length) | ||
+ return 0; /* silently discard */ | ||
+ hbtype = *p++; | ||
+ n2s(p, payload); | ||
+ if (1 + 2 + payload + 16 > s->s3->rrec.length) | ||
+ return 0; /* silently discard per RFC 6520 sec. 4 */ | ||
+ pl = p; | ||
+ | ||
if (hbtype == TLS1_HB_REQUEST) | ||
{ | ||
unsigned char *buffer, *bp; | ||
+ unsigned int write_length = 1 /* heartbeat type */ + | ||
+ 2 /* heartbeat length */ + | ||
+ payload + padding; | ||
int r; | ||
|
||
+ if (write_length > SSL3_RT_MAX_PLAIN_LENGTH) | ||
+ return 0; | ||
+ | ||
/* Allocate memory for the response, size is 1 byte | ||
* message type, plus 2 bytes payload length, plus | ||
* payload, plus padding | ||
*/ | ||
- buffer = OPENSSL_malloc(1 + 2 + payload + padding); | ||
+ buffer = OPENSSL_malloc(write_length); | ||
bp = buffer; | ||
|
||
/* Enter response type, length and copy payload */ | ||
@@ -1482,11 +1492,11 @@ dtls1_process_heartbeat(SSL *s) | ||
/* Random padding */ | ||
RAND_pseudo_bytes(bp, padding); | ||
|
||
- r = dtls1_write_bytes(s, TLS1_RT_HEARTBEAT, buffer, 3 + payload + padding); | ||
+ r = dtls1_write_bytes(s, TLS1_RT_HEARTBEAT, buffer, write_length); | ||
|
||
if (r >= 0 && s->msg_callback) | ||
s->msg_callback(1, s->version, TLS1_RT_HEARTBEAT, | ||
- buffer, 3 + payload + padding, | ||
+ buffer, write_length, | ||
s, s->msg_callback_arg); | ||
|
||
OPENSSL_free(buffer); | ||
diff --git a/external/openssl/ssl/t1_lib.c b/external/openssl/ssl/t1_lib.c | ||
index f170056..4e12d3c 100644 | ||
--- a/external/openssl/ssl/t1_lib.c | ||
+++ b/external/openssl/ssl/t1_lib.c | ||
@@ -2647,16 +2647,20 @@ tls1_process_heartbeat(SSL *s) | ||
unsigned int payload; | ||
unsigned int padding = 16; /* Use minimum padding */ | ||
|
||
- /* Read type and payload length first */ | ||
- hbtype = *p++; | ||
- n2s(p, payload); | ||
- pl = p; | ||
- | ||
if (s->msg_callback) | ||
s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT, | ||
&s->s3->rrec.data[0], s->s3->rrec.length, | ||
s, s->msg_callback_arg); | ||
|
||
+ /* Read type and payload length first */ | ||
+ if (1 + 2 + 16 > s->s3->rrec.length) | ||
+ return 0; /* silently discard */ | ||
+ hbtype = *p++; | ||
+ n2s(p, payload); | ||
+ if (1 + 2 + payload + 16 > s->s3->rrec.length) | ||
+ return 0; /* silently discard per RFC 6520 sec. 4 */ | ||
+ pl = p; | ||
+ | ||
if (hbtype == TLS1_HB_REQUEST) | ||
{ | ||
unsigned char *buffer, *bp; | ||
-- | ||
1.8.3.2 |