Commit 661bccb5 authored by Pieter Hintjens's avatar Pieter Hintjens

Merge pull request #1250 from c-rack/master

No error-checking of setsockopt ZMQ_CURVE_* z85 keys. Solves #1094.
parents 6d9f97ad e00ea532
......@@ -376,20 +376,22 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
}
else
if (optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
zmq_z85_decode (curve_public_key, (char *) optval_);
if (zmq_z85_decode (curve_public_key, (char *) optval_)) {
mechanism = ZMQ_CURVE;
return 0;
}
}
else
// Deprecated, not symmetrical with zmq_getsockopt
if (optvallen_ == CURVE_KEYSIZE_Z85) {
char z85_key [41];
char z85_key [CURVE_KEYSIZE_Z85 + 1];
memcpy (z85_key, (char *) optval_, CURVE_KEYSIZE_Z85);
z85_key [CURVE_KEYSIZE_Z85] = 0;
zmq_z85_decode (curve_public_key, z85_key);
if (zmq_z85_decode (curve_public_key, z85_key)) {
mechanism = ZMQ_CURVE;
return 0;
}
}
break;
case ZMQ_CURVE_SECRETKEY:
......@@ -400,20 +402,22 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
}
else
if (optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
zmq_z85_decode (curve_secret_key, (char *) optval_);
if (zmq_z85_decode (curve_secret_key, (char *) optval_)) {
mechanism = ZMQ_CURVE;
return 0;
}
}
else
// Deprecated, not symmetrical with zmq_getsockopt
if (optvallen_ == CURVE_KEYSIZE_Z85) {
char z85_key [41];
char z85_key [CURVE_KEYSIZE_Z85 + 1];
memcpy (z85_key, (char *) optval_, CURVE_KEYSIZE_Z85);
z85_key [CURVE_KEYSIZE_Z85] = 0;
zmq_z85_decode (curve_secret_key, z85_key);
if (zmq_z85_decode (curve_secret_key, z85_key)) {
mechanism = ZMQ_CURVE;
return 0;
}
}
break;
case ZMQ_CURVE_SERVERKEY:
......@@ -425,22 +429,24 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
}
else
if (optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
zmq_z85_decode (curve_server_key, (char *) optval_);
if (zmq_z85_decode (curve_server_key, (char *) optval_)) {
mechanism = ZMQ_CURVE;
as_server = 0;
return 0;
}
}
else
// Deprecated, not symmetrical with zmq_getsockopt
if (optvallen_ == CURVE_KEYSIZE_Z85) {
char z85_key [41];
char z85_key [CURVE_KEYSIZE_Z85 + 1];
memcpy (z85_key, (char *) optval_, CURVE_KEYSIZE_Z85);
z85_key [CURVE_KEYSIZE_Z85] = 0;
zmq_z85_decode (curve_server_key, z85_key);
if (zmq_z85_decode (curve_server_key, z85_key)) {
mechanism = ZMQ_CURVE;
as_server = 0;
return 0;
}
}
break;
# endif
......
......@@ -218,6 +218,21 @@ int main (void)
expect_bounce_fail (server, client);
close_zero_linger (client);
// Check return codes for invalid buffer sizes
client = zmq_socket (ctx, ZMQ_DEALER);
assert (client);
errno = 0;
rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, server_public, 123);
assert (rc == -1 && errno == EINVAL);
errno = 0;
rc = zmq_setsockopt (client, ZMQ_CURVE_PUBLICKEY, client_public, 123);
assert (rc == -1 && errno == EINVAL);
errno = 0;
rc = zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY, client_secret, 123);
assert (rc == -1 && errno == EINVAL);
rc = zmq_close (client);
assert (rc == 0);
// Shutdown
rc = zmq_close (server);
assert (rc == 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment