Commit 1844fc32 authored by Constantin Rack's avatar Constantin Rack

Problem: No error-checking of setsockopt ZMQ_CURVE_* z85 keys. Solves #1094.

parent 6d9f97ad
...@@ -376,19 +376,21 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, ...@@ -376,19 +376,21 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
} }
else else
if (optvallen_ == CURVE_KEYSIZE_Z85 + 1) { 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; mechanism = ZMQ_CURVE;
return 0; return 0;
}
} }
else else
// Deprecated, not symmetrical with zmq_getsockopt // Deprecated, not symmetrical with zmq_getsockopt
if (optvallen_ == CURVE_KEYSIZE_Z85) { if (optvallen_ == CURVE_KEYSIZE_Z85) {
char z85_key [41]; char z85_key [CURVE_KEYSIZE_Z85 + 1];
memcpy (z85_key, (char *) optval_, CURVE_KEYSIZE_Z85); memcpy (z85_key, (char *) optval_, CURVE_KEYSIZE_Z85);
z85_key [CURVE_KEYSIZE_Z85] = 0; 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; mechanism = ZMQ_CURVE;
return 0; return 0;
}
} }
break; break;
...@@ -400,19 +402,21 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, ...@@ -400,19 +402,21 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
} }
else else
if (optvallen_ == CURVE_KEYSIZE_Z85 + 1) { 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; mechanism = ZMQ_CURVE;
return 0; return 0;
}
} }
else else
// Deprecated, not symmetrical with zmq_getsockopt // Deprecated, not symmetrical with zmq_getsockopt
if (optvallen_ == CURVE_KEYSIZE_Z85) { if (optvallen_ == CURVE_KEYSIZE_Z85) {
char z85_key [41]; char z85_key [CURVE_KEYSIZE_Z85 + 1];
memcpy (z85_key, (char *) optval_, CURVE_KEYSIZE_Z85); memcpy (z85_key, (char *) optval_, CURVE_KEYSIZE_Z85);
z85_key [CURVE_KEYSIZE_Z85] = 0; 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; mechanism = ZMQ_CURVE;
return 0; return 0;
}
} }
break; break;
...@@ -425,21 +429,23 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, ...@@ -425,21 +429,23 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
} }
else else
if (optvallen_ == CURVE_KEYSIZE_Z85 + 1) { 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; mechanism = ZMQ_CURVE;
as_server = 0; as_server = 0;
return 0; return 0;
}
} }
else else
// Deprecated, not symmetrical with zmq_getsockopt // Deprecated, not symmetrical with zmq_getsockopt
if (optvallen_ == CURVE_KEYSIZE_Z85) { if (optvallen_ == CURVE_KEYSIZE_Z85) {
char z85_key [41]; char z85_key [CURVE_KEYSIZE_Z85 + 1];
memcpy (z85_key, (char *) optval_, CURVE_KEYSIZE_Z85); memcpy (z85_key, (char *) optval_, CURVE_KEYSIZE_Z85);
z85_key [CURVE_KEYSIZE_Z85] = 0; 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; mechanism = ZMQ_CURVE;
as_server = 0; as_server = 0;
return 0; return 0;
}
} }
break; break;
# endif # endif
......
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