1 From 479db2113643e459c11db392e0fefd6400657c9e Mon Sep 17 00:00:00 2001
2 From: Constantin Rack <constantin@rack.li>
3 Date: Sat, 8 Nov 2014 10:50:17 +0100
4 Subject: [PATCH] Problem: return code of sodium_init() is not checked.
6 There are two todo comments in curve_client.cpp and curve_server.cpp that suggest
7 checking the return code of sodium_init() call. sodium_init() returns -1 on error,
8 0 on success and 1 if it has been called before and is already initalized:
9 https://github.com/jedisct1/libsodium/blob/master/src/libsodium/sodium/core.c
11 Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
15 diff --git a/src/curve_client.cpp b/src/curve_client.cpp
16 index 6019c54..77fc420 100644
17 --- a/src/curve_client.cpp
18 +++ b/src/curve_client.cpp
19 @@ -38,6 +38,7 @@ zmq::curve_client_t::curve_client_t (const options_t &options_) :
24 memcpy (public_key, options_.curve_public_key, crypto_box_PUBLICKEYBYTES);
25 memcpy (secret_key, options_.curve_secret_key, crypto_box_SECRETKEYBYTES);
26 memcpy (server_key, options_.curve_server_key, crypto_box_PUBLICKEYBYTES);
27 @@ -47,12 +48,12 @@ zmq::curve_client_t::curve_client_t (const options_t &options_) :
28 unsigned char tmpbytes[4];
29 randombytes(tmpbytes, 4);
31 - // todo check return code
33 + rc = sodium_init ();
34 + zmq_assert (rc != -1);
37 // Generate short-term key pair
38 - const int rc = crypto_box_keypair (cn_public, cn_secret);
39 + rc = crypto_box_keypair (cn_public, cn_secret);
43 diff --git a/src/curve_server.cpp b/src/curve_server.cpp
44 index a3c4243..22c32d6 100644
45 --- a/src/curve_server.cpp
46 +++ b/src/curve_server.cpp
47 @@ -42,6 +42,7 @@ zmq::curve_server_t::curve_server_t (session_base_t *session_,
52 // Fetch our secret key from socket options
53 memcpy (secret_key, options_.curve_secret_key, crypto_box_SECRETKEYBYTES);
54 scoped_lock_t lock (sync);
55 @@ -50,12 +51,12 @@ zmq::curve_server_t::curve_server_t (session_base_t *session_,
56 unsigned char tmpbytes[4];
57 randombytes(tmpbytes, 4);
59 - // todo check return code
61 + rc = sodium_init ();
62 + zmq_assert (rc != -1);
65 // Generate short-term key pair
66 - const int rc = crypto_box_keypair (cn_public, cn_secret);
67 + rc = crypto_box_keypair (cn_public, cn_secret);