From d7c8021afce92b1df0d986b908a0e885387aba1f Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Mon, 4 Nov 2013 15:39:20 +0100 Subject: [PATCH 1/2] Fixed issue 578 --- .gitignore | 9 +++++++++ src/zmq_utils.cpp | 11 ++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 3e8c1652..66f55190 100644 --- a/.gitignore +++ b/.gitignore @@ -72,6 +72,15 @@ tests/test_security_null tests/test_security_plain tests/test_proxy tests/test_abstract_ipc +tests/test_connect_delay_tipc +tests/test_pair_tipc +tests/test_reqrep_device_tipc +tests/test_reqrep_tipc +tests/test_router_handover +tests/test_router_mandatory_tipc +tests/test_shutdown_stress_tipc +tests/test_sub_forward_tipc +tests/test_term_endpoint_tipc tests/test*.log tests/test*.trs src/platform.hpp* diff --git a/src/zmq_utils.cpp b/src/zmq_utils.cpp index acefe717..c20a2ec8 100644 --- a/src/zmq_utils.cpp +++ b/src/zmq_utils.cpp @@ -142,7 +142,6 @@ char *zmq_z85_encode (char *dest, uint8_t *data, size_t size) uint8_t *zmq_z85_decode (uint8_t *dest, char *string) { - if (strlen (string) % 5 != 0) { errno = EINVAL; return NULL; @@ -150,7 +149,8 @@ uint8_t *zmq_z85_decode (uint8_t *dest, char *string) unsigned int byte_nbr = 0; unsigned int char_nbr = 0; uint32_t value = 0; - while (char_nbr < strlen (string)) { + uint string_len = strlen (string); + while (char_nbr < string_len) { // Accumulate value in base 85 value = value * 85 + decoder [(uint8_t) string [char_nbr++] - 32]; if (char_nbr % 5 == 0) { @@ -173,7 +173,7 @@ uint8_t *zmq_z85_decode (uint8_t *dest, char *string) // Returns 0 on success, -1 on failure, setting errno. // Sets errno = ENOTSUP in the absence of libsodium. -int zmq_curve_keypair (char* z85_public_key, char *z85_secret_key) +int zmq_curve_keypair (char *z85_public_key, char *z85_secret_key) { #ifdef HAVE_LIBSODIUM # if crypto_box_PUBLICKEYBYTES != 32 \ @@ -185,8 +185,9 @@ int zmq_curve_keypair (char* z85_public_key, char *z85_secret_key) uint8_t secret_key [32]; int rc = crypto_box_keypair (public_key, secret_key); - // is there a sensible errno to set here? - if (rc) return rc; + // Is there a sensible errno to set here? + if (rc) + return rc; zmq_z85_encode (z85_public_key, public_key, 32); zmq_z85_encode (z85_secret_key, secret_key, 32); From 5e6aa58a140767b055d461ab13e71281e9a7996d Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Mon, 4 Nov 2013 16:04:13 +0100 Subject: [PATCH 2/2] Fixed issue 578 - corrected type usage --- src/zmq_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zmq_utils.cpp b/src/zmq_utils.cpp index c20a2ec8..148ef95f 100644 --- a/src/zmq_utils.cpp +++ b/src/zmq_utils.cpp @@ -148,8 +148,8 @@ uint8_t *zmq_z85_decode (uint8_t *dest, char *string) } unsigned int byte_nbr = 0; unsigned int char_nbr = 0; + unsigned int string_len = strlen (string); uint32_t value = 0; - uint string_len = strlen (string); while (char_nbr < string_len) { // Accumulate value in base 85 value = value * 85 + decoder [(uint8_t) string [char_nbr++] - 32];