Problem: MSAN complains about uninitialised buffers in CURVE greetings

Solution: memset some of the CURVE greetings buffers. Most likely false
positives, but easier to fix here than convince Clang of being wrong.
This commit is contained in:
Luca Boccassi 2020-05-21 13:56:02 +01:00 committed by Luca Boccassi
parent 35c4c22c81
commit 38349198a6
2 changed files with 9 additions and 0 deletions

View File

@ -161,6 +161,7 @@ struct curve_client_tools_t
memcpy (&vouch_plaintext[crypto_box_ZEROBYTES], cn_public_, 32);
memcpy (&vouch_plaintext[crypto_box_ZEROBYTES + 32], server_key_, 32);
memset (vouch_nonce, 0, crypto_box_NONCEBYTES);
memcpy (vouch_nonce, "VOUCH---", 8);
randombytes (vouch_nonce + 8, 16);
@ -246,6 +247,8 @@ struct curve_client_tools_t
memcpy (server_key, curve_server_key_, crypto_box_PUBLICKEYBYTES);
// Generate short-term key pair
memset (cn_secret, 0, crypto_box_SECRETKEYBYTES);
memset (cn_public, 0, crypto_box_PUBLICKEYBYTES);
rc = crypto_box_keypair (cn_public, cn_secret);
zmq_assert (rc == 0);
}

View File

@ -57,6 +57,8 @@ zmq::curve_server_t::curve_server_t (session_base_t *session_,
memcpy (_secret_key, options_.curve_secret_key, crypto_box_SECRETKEYBYTES);
// Generate short-term key pair
memset (_cn_secret, 0, crypto_box_SECRETKEYBYTES);
memset (_cn_public, 0, crypto_box_PUBLICKEYBYTES);
rc = crypto_box_keypair (_cn_public, _cn_secret);
zmq_assert (rc == 0);
}
@ -214,6 +216,7 @@ int zmq::curve_server_t::produce_welcome (msg_t *msg_)
// Create full nonce for encryption
// 8-byte prefix plus 16-byte random nonce
memset (cookie_nonce, 0, crypto_secretbox_NONCEBYTES);
memcpy (cookie_nonce, "COOKIE--", 8);
randombytes (cookie_nonce + 8, 16);
@ -224,6 +227,7 @@ int zmq::curve_server_t::produce_welcome (msg_t *msg_)
memcpy (&cookie_plaintext[crypto_secretbox_ZEROBYTES + 32], _cn_secret, 32);
// Generate fresh cookie key
memset (_cookie_key, 0, crypto_secretbox_KEYBYTES);
randombytes (_cookie_key, crypto_secretbox_KEYBYTES);
// Encrypt using symmetric cookie key
@ -239,6 +243,7 @@ int zmq::curve_server_t::produce_welcome (msg_t *msg_)
// Create full nonce for encryption
// 8-byte prefix plus 16-byte random nonce
memset (welcome_nonce, 0, crypto_box_NONCEBYTES);
memcpy (welcome_nonce, "WELCOME-", 8);
randombytes (welcome_nonce + 8, crypto_box_NONCEBYTES - 8);
@ -373,6 +378,7 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
memcpy (vouch_box + crypto_box_BOXZEROBYTES,
&initiate_plaintext[crypto_box_ZEROBYTES + 48], 80);
memset (vouch_nonce, 0, crypto_box_NONCEBYTES);
memcpy (vouch_nonce, "VOUCH---", 8);
memcpy (vouch_nonce + 8, &initiate_plaintext[crypto_box_ZEROBYTES + 32],
16);