summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authordjm <>2014-04-07 23:57:27 +0000
committerdjm <>2014-04-07 23:57:27 +0000
commitf7eb965a357993008aede65496a25104a2f6451e (patch)
treea00370115283c41575628e485eb2314eb6408581 /src/lib
parent13f636333bbcb2ffb5175d237e6113352938d8e7 (diff)
downloadopenbsd-f7eb965a357993008aede65496a25104a2f6451e.tar.gz
openbsd-f7eb965a357993008aede65496a25104a2f6451e.tar.bz2
openbsd-f7eb965a357993008aede65496a25104a2f6451e.zip
cherrypick fix for CVE-2014-0160 "heartbleed" vulnerability from
OpenSSL git; ok sthen@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libssl/d1_both.c26
-rw-r--r--src/lib/libssl/src/ssl/d1_both.c26
-rw-r--r--src/lib/libssl/src/ssl/t1_lib.c14
-rw-r--r--src/lib/libssl/t1_lib.c14
4 files changed, 54 insertions, 26 deletions
diff --git a/src/lib/libssl/d1_both.c b/src/lib/libssl/d1_both.c
index 72b3b20ae4..e4b718efa7 100644
--- a/src/lib/libssl/d1_both.c
+++ b/src/lib/libssl/d1_both.c
@@ -1459,26 +1459,36 @@ dtls1_process_heartbeat(SSL *s)
1459 unsigned int payload; 1459 unsigned int payload;
1460 unsigned int padding = 16; /* Use minimum padding */ 1460 unsigned int padding = 16; /* Use minimum padding */
1461 1461
1462 /* Read type and payload length first */
1463 hbtype = *p++;
1464 n2s(p, payload);
1465 pl = p;
1466
1467 if (s->msg_callback) 1462 if (s->msg_callback)
1468 s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT, 1463 s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT,
1469 &s->s3->rrec.data[0], s->s3->rrec.length, 1464 &s->s3->rrec.data[0], s->s3->rrec.length,
1470 s, s->msg_callback_arg); 1465 s, s->msg_callback_arg);
1471 1466
1467 /* Read type and payload length first */
1468 if (1 + 2 + 16 > s->s3->rrec.length)
1469 return 0; /* silently discard */
1470 hbtype = *p++;
1471 n2s(p, payload);
1472 if (1 + 2 + payload + 16 > s->s3->rrec.length)
1473 return 0; /* silently discard per RFC 6520 sec. 4 */
1474 pl = p;
1475
1472 if (hbtype == TLS1_HB_REQUEST) 1476 if (hbtype == TLS1_HB_REQUEST)
1473 { 1477 {
1474 unsigned char *buffer, *bp; 1478 unsigned char *buffer, *bp;
1479 unsigned int write_length = 1 /* heartbeat type */ +
1480 2 /* heartbeat length */ +
1481 payload + padding;
1475 int r; 1482 int r;
1476 1483
1484 if (write_length > SSL3_RT_MAX_PLAIN_LENGTH)
1485 return 0;
1486
1477 /* Allocate memory for the response, size is 1 byte 1487 /* Allocate memory for the response, size is 1 byte
1478 * message type, plus 2 bytes payload length, plus 1488 * message type, plus 2 bytes payload length, plus
1479 * payload, plus padding 1489 * payload, plus padding
1480 */ 1490 */
1481 buffer = OPENSSL_malloc(1 + 2 + payload + padding); 1491 buffer = OPENSSL_malloc(write_length);
1482 bp = buffer; 1492 bp = buffer;
1483 1493
1484 /* Enter response type, length and copy payload */ 1494 /* Enter response type, length and copy payload */
@@ -1489,11 +1499,11 @@ dtls1_process_heartbeat(SSL *s)
1489 /* Random padding */ 1499 /* Random padding */
1490 RAND_pseudo_bytes(bp, padding); 1500 RAND_pseudo_bytes(bp, padding);
1491 1501
1492 r = dtls1_write_bytes(s, TLS1_RT_HEARTBEAT, buffer, 3 + payload + padding); 1502 r = dtls1_write_bytes(s, TLS1_RT_HEARTBEAT, buffer, write_length);
1493 1503
1494 if (r >= 0 && s->msg_callback) 1504 if (r >= 0 && s->msg_callback)
1495 s->msg_callback(1, s->version, TLS1_RT_HEARTBEAT, 1505 s->msg_callback(1, s->version, TLS1_RT_HEARTBEAT,
1496 buffer, 3 + payload + padding, 1506 buffer, write_length,
1497 s, s->msg_callback_arg); 1507 s, s->msg_callback_arg);
1498 1508
1499 OPENSSL_free(buffer); 1509 OPENSSL_free(buffer);
diff --git a/src/lib/libssl/src/ssl/d1_both.c b/src/lib/libssl/src/ssl/d1_both.c
index 72b3b20ae4..e4b718efa7 100644
--- a/src/lib/libssl/src/ssl/d1_both.c
+++ b/src/lib/libssl/src/ssl/d1_both.c
@@ -1459,26 +1459,36 @@ dtls1_process_heartbeat(SSL *s)
1459 unsigned int payload; 1459 unsigned int payload;
1460 unsigned int padding = 16; /* Use minimum padding */ 1460 unsigned int padding = 16; /* Use minimum padding */
1461 1461
1462 /* Read type and payload length first */
1463 hbtype = *p++;
1464 n2s(p, payload);
1465 pl = p;
1466
1467 if (s->msg_callback) 1462 if (s->msg_callback)
1468 s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT, 1463 s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT,
1469 &s->s3->rrec.data[0], s->s3->rrec.length, 1464 &s->s3->rrec.data[0], s->s3->rrec.length,
1470 s, s->msg_callback_arg); 1465 s, s->msg_callback_arg);
1471 1466
1467 /* Read type and payload length first */
1468 if (1 + 2 + 16 > s->s3->rrec.length)
1469 return 0; /* silently discard */
1470 hbtype = *p++;
1471 n2s(p, payload);
1472 if (1 + 2 + payload + 16 > s->s3->rrec.length)
1473 return 0; /* silently discard per RFC 6520 sec. 4 */
1474 pl = p;
1475
1472 if (hbtype == TLS1_HB_REQUEST) 1476 if (hbtype == TLS1_HB_REQUEST)
1473 { 1477 {
1474 unsigned char *buffer, *bp; 1478 unsigned char *buffer, *bp;
1479 unsigned int write_length = 1 /* heartbeat type */ +
1480 2 /* heartbeat length */ +
1481 payload + padding;
1475 int r; 1482 int r;
1476 1483
1484 if (write_length > SSL3_RT_MAX_PLAIN_LENGTH)
1485 return 0;
1486
1477 /* Allocate memory for the response, size is 1 byte 1487 /* Allocate memory for the response, size is 1 byte
1478 * message type, plus 2 bytes payload length, plus 1488 * message type, plus 2 bytes payload length, plus
1479 * payload, plus padding 1489 * payload, plus padding
1480 */ 1490 */
1481 buffer = OPENSSL_malloc(1 + 2 + payload + padding); 1491 buffer = OPENSSL_malloc(write_length);
1482 bp = buffer; 1492 bp = buffer;
1483 1493
1484 /* Enter response type, length and copy payload */ 1494 /* Enter response type, length and copy payload */
@@ -1489,11 +1499,11 @@ dtls1_process_heartbeat(SSL *s)
1489 /* Random padding */ 1499 /* Random padding */
1490 RAND_pseudo_bytes(bp, padding); 1500 RAND_pseudo_bytes(bp, padding);
1491 1501
1492 r = dtls1_write_bytes(s, TLS1_RT_HEARTBEAT, buffer, 3 + payload + padding); 1502 r = dtls1_write_bytes(s, TLS1_RT_HEARTBEAT, buffer, write_length);
1493 1503
1494 if (r >= 0 && s->msg_callback) 1504 if (r >= 0 && s->msg_callback)
1495 s->msg_callback(1, s->version, TLS1_RT_HEARTBEAT, 1505 s->msg_callback(1, s->version, TLS1_RT_HEARTBEAT,
1496 buffer, 3 + payload + padding, 1506 buffer, write_length,
1497 s, s->msg_callback_arg); 1507 s, s->msg_callback_arg);
1498 1508
1499 OPENSSL_free(buffer); 1509 OPENSSL_free(buffer);
diff --git a/src/lib/libssl/src/ssl/t1_lib.c b/src/lib/libssl/src/ssl/t1_lib.c
index bfd4731365..a649dafba9 100644
--- a/src/lib/libssl/src/ssl/t1_lib.c
+++ b/src/lib/libssl/src/ssl/t1_lib.c
@@ -2441,16 +2441,20 @@ tls1_process_heartbeat(SSL *s)
2441 unsigned int payload; 2441 unsigned int payload;
2442 unsigned int padding = 16; /* Use minimum padding */ 2442 unsigned int padding = 16; /* Use minimum padding */
2443 2443
2444 /* Read type and payload length first */
2445 hbtype = *p++;
2446 n2s(p, payload);
2447 pl = p;
2448
2449 if (s->msg_callback) 2444 if (s->msg_callback)
2450 s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT, 2445 s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT,
2451 &s->s3->rrec.data[0], s->s3->rrec.length, 2446 &s->s3->rrec.data[0], s->s3->rrec.length,
2452 s, s->msg_callback_arg); 2447 s, s->msg_callback_arg);
2453 2448
2449 /* Read type and payload length first */
2450 if (1 + 2 + 16 > s->s3->rrec.length)
2451 return 0; /* silently discard */
2452 hbtype = *p++;
2453 n2s(p, payload);
2454 if (1 + 2 + payload + 16 > s->s3->rrec.length)
2455 return 0; /* silently discard per RFC 6520 sec. 4 */
2456 pl = p;
2457
2454 if (hbtype == TLS1_HB_REQUEST) 2458 if (hbtype == TLS1_HB_REQUEST)
2455 { 2459 {
2456 unsigned char *buffer, *bp; 2460 unsigned char *buffer, *bp;
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c
index bfd4731365..a649dafba9 100644
--- a/src/lib/libssl/t1_lib.c
+++ b/src/lib/libssl/t1_lib.c
@@ -2441,16 +2441,20 @@ tls1_process_heartbeat(SSL *s)
2441 unsigned int payload; 2441 unsigned int payload;
2442 unsigned int padding = 16; /* Use minimum padding */ 2442 unsigned int padding = 16; /* Use minimum padding */
2443 2443
2444 /* Read type and payload length first */
2445 hbtype = *p++;
2446 n2s(p, payload);
2447 pl = p;
2448
2449 if (s->msg_callback) 2444 if (s->msg_callback)
2450 s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT, 2445 s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT,
2451 &s->s3->rrec.data[0], s->s3->rrec.length, 2446 &s->s3->rrec.data[0], s->s3->rrec.length,
2452 s, s->msg_callback_arg); 2447 s, s->msg_callback_arg);
2453 2448
2449 /* Read type and payload length first */
2450 if (1 + 2 + 16 > s->s3->rrec.length)
2451 return 0; /* silently discard */
2452 hbtype = *p++;
2453 n2s(p, payload);
2454 if (1 + 2 + payload + 16 > s->s3->rrec.length)
2455 return 0; /* silently discard per RFC 6520 sec. 4 */
2456 pl = p;
2457
2454 if (hbtype == TLS1_HB_REQUEST) 2458 if (hbtype == TLS1_HB_REQUEST)
2455 { 2459 {
2456 unsigned char *buffer, *bp; 2460 unsigned char *buffer, *bp;