aboutsummaryrefslogtreecommitdiffstats
path: root/main/zeromq/CVE-2019-13132.patch
blob: 39c80d7996e69b4d53f4934c7ccce566b12f7360 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
From 4287cd2274ad48faa2b5346b6108f05b32ec20f2 Mon Sep 17 00:00:00 2001
From: Luca Boccassi <luca.boccassi@gmail.com>
Date: Tue, 2 Jul 2019 01:24:19 +0100
Subject: [PATCH] Problem: application metadata not parsed correctly when using
 CURVE

Solution: create buffers large enough to contain arbitrary metadata
---
 src/curve_server.cpp | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/src/curve_server.cpp b/src/curve_server.cpp
index 6938a637..d3a710db 100644
--- a/src/curve_server.cpp
+++ b/src/curve_server.cpp
@@ -327,8 +327,12 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
     const size_t clen = (size - 113) + crypto_box_BOXZEROBYTES;
 
     uint8_t initiate_nonce[crypto_box_NONCEBYTES];
-    uint8_t initiate_plaintext[crypto_box_ZEROBYTES + 128 + 256];
-    uint8_t initiate_box[crypto_box_BOXZEROBYTES + 144 + 256];
+    uint8_t *initiate_plaintext =
+      static_cast<uint8_t *> (malloc (crypto_box_ZEROBYTES + clen));
+    alloc_assert (initiate_plaintext);
+    uint8_t *initiate_box =
+      static_cast<uint8_t *> (malloc (crypto_box_BOXZEROBYTES + clen));
+    alloc_assert (initiate_box);
 
     //  Open Box [C + vouch + metadata](C'->S')
     memset (initiate_box, 0, crypto_box_BOXZEROBYTES);
@@ -339,6 +343,8 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
     memcpy (initiate_nonce + 16, initiate + 105, 8);
     cn_peer_nonce = get_uint64 (initiate + 105);
 
+    const uint8_t *client_key = initiate_plaintext + crypto_box_ZEROBYTES;
+
     rc = crypto_box_open (initiate_plaintext, initiate_box, clen,
                           initiate_nonce, cn_client, cn_secret);
     if (rc != 0) {
@@ -346,11 +352,10 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
         session->get_socket ()->event_handshake_failed_protocol (
           session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
         errno = EPROTO;
-        return -1;
+        rc = -1;
+        goto exit;
     }
 
-    const uint8_t *client_key = initiate_plaintext + crypto_box_ZEROBYTES;
-
     uint8_t vouch_nonce[crypto_box_NONCEBYTES];
     uint8_t vouch_plaintext[crypto_box_ZEROBYTES + 64];
     uint8_t vouch_box[crypto_box_BOXZEROBYTES + 80];
@@ -371,7 +376,8 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
         session->get_socket ()->event_handshake_failed_protocol (
           session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
         errno = EPROTO;
-        return -1;
+        rc = -1;
+        goto exit;
     }
 
     //  What we decrypted must be the client's short-term public key
@@ -383,7 +389,8 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
         session->get_socket ()->event_handshake_failed_protocol (
           session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_KEY_EXCHANGE);
         errno = EPROTO;
-        return -1;
+        rc = -1;
+        goto exit;
     }
 
     //  Precompute connection secret from client key
@@ -405,7 +412,7 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
             //  is attempted)
             rc = receive_and_process_zap_reply ();
             if (rc == -1)
-                return -1;
+                goto exit;
         } else if (!options.zap_enforce_domain) {
             //  This supports the Stonehouse pattern (encryption without
             //  authentication) in legacy mode (domain set but no handler).
@@ -413,15 +420,21 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
         } else {
             session->get_socket ()->event_handshake_failed_no_detail (
               session->get_endpoint (), EFAULT);
-            return -1;
+            rc = -1;
+            goto exit;
         }
     } else {
         //  This supports the Stonehouse pattern (encryption without authentication).
         state = sending_ready;
     }
 
-    return parse_metadata (initiate_plaintext + crypto_box_ZEROBYTES + 128,
-                           clen - crypto_box_ZEROBYTES - 128);
+    rc = parse_metadata (initiate_plaintext + crypto_box_ZEROBYTES + 128,
+                         clen - crypto_box_ZEROBYTES - 128);
+
+exit:
+    free (initiate_plaintext);
+    free (initiate_box);
+    return rc;
 }
 
 int zmq::curve_server_t::produce_ready (msg_t *msg_)
-- 
2.20.1