From bab213e7945b03bf595bf7c36ef61421cf202ff3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 25 Nov 2021 09:43:01 +0100 Subject: [PATCH] work on #7099 --- src/util/crypto_helper_common.c | 2 +- src/util/crypto_helper_esign.c | 6 +- src/util/crypto_helper_rsa.c | 17 +++-- src/util/secmod_common.c | 119 +++++++++++++++----------------- 4 files changed, 71 insertions(+), 73 deletions(-) diff --git a/src/util/crypto_helper_common.c b/src/util/crypto_helper_common.c index b89ee847c..9eddb7dcb 100644 --- a/src/util/crypto_helper_common.c +++ b/src/util/crypto_helper_common.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2020 Taler Systems SA + Copyright (C) 2020, 2021 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software diff --git a/src/util/crypto_helper_esign.c b/src/util/crypto_helper_esign.c index a73e96889..702ea74df 100644 --- a/src/util/crypto_helper_esign.c +++ b/src/util/crypto_helper_esign.c @@ -387,8 +387,8 @@ TALER_CRYPTO_helper_esign_sign_ ( uint16_t msize; ret = recv (esh->sock, - buf, - sizeof (buf), + &buf[off], + sizeof (buf) - off, (finished && (0 == off)) ? MSG_DONTWAIT : 0); @@ -410,6 +410,8 @@ TALER_CRYPTO_helper_esign_sign_ ( if (0 == ret) { GNUNET_break (0 == off); + if (finished) + return TALER_EC_NONE; return TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG; } off += ret; diff --git a/src/util/crypto_helper_rsa.c b/src/util/crypto_helper_rsa.c index f9c4d60fc..85741d5e5 100644 --- a/src/util/crypto_helper_rsa.c +++ b/src/util/crypto_helper_rsa.c @@ -445,8 +445,8 @@ TALER_CRYPTO_helper_rsa_sign ( ssize_t ret; ret = recv (dh->sock, - buf, - sizeof (buf), + &buf[off], + sizeof (buf) - off, (finished && (0 == off)) ? MSG_DONTWAIT : 0); @@ -483,8 +483,14 @@ more: switch (ntohs (hdr->type)) { case TALER_HELPER_RSA_MT_RES_SIGNATURE: - if ( (msize < sizeof (struct TALER_CRYPTO_SignResponse)) || - (finished) ) + if (msize < sizeof (struct TALER_CRYPTO_SignResponse)) + { + GNUNET_break_op (0); + do_disconnect (dh); + *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; + goto end; + } + if (finished) { GNUNET_break_op (0); do_disconnect (dh); @@ -525,7 +531,8 @@ more: (const struct TALER_CRYPTO_SignFailure *) buf; *ec = (enum TALER_ErrorCode) ntohl (sf->ec); - return ds; + finished = true; + break; } case TALER_HELPER_RSA_MT_AVAIL: if (GNUNET_OK != diff --git a/src/util/secmod_common.c b/src/util/secmod_common.c index 11d7bf712..33b880d2c 100644 --- a/src/util/secmod_common.c +++ b/src/util/secmod_common.c @@ -194,9 +194,6 @@ cleanup: } -/** - * Send a signal to all clients to notify them about a key generation change. - */ void TES_wake_clients (void) { @@ -216,13 +213,6 @@ TES_wake_clients (void) } -/** - * Read work request from the client. - * - * @param cls a `struct TES_Client *` - * @param dispatch function to call with work requests received - * @return #GNUNET_OK on success - */ enum GNUNET_GenericReturnValue TES_read_work (void *cls, TES_MessageDispatch dispatch) @@ -234,67 +224,66 @@ TES_read_work (void *cls, const struct GNUNET_MessageHeader *hdr; enum GNUNET_GenericReturnValue ret; - while (1) + do { - do + ssize_t recv_size; + + recv_size = recv (client->csock, + &buf[off], + sizeof (client->iobuf) - off, + 0); + if (-1 == recv_size) { - ssize_t recv_size; - - recv_size = recv (client->csock, - &buf[off], - sizeof (client->iobuf) - off, - 0); - if (-1 == recv_size) + if ( (0 == off) && + (EAGAIN == errno) ) + return GNUNET_NO; + if ( (EINTR == errno) || + (EAGAIN == errno) ) { - if ( (0 == off) && - (EAGAIN == errno) ) - return GNUNET_NO; - if ( (EINTR == errno) || - (EAGAIN == errno) ) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, - "recv"); - continue; - } - if (ECONNRESET != errno) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, - "recv"); - return GNUNET_SYSERR; - } - if (0 == recv_size) - { - /* regular disconnect? */ - GNUNET_break_op (0 == off); - return GNUNET_SYSERR; - } - off += recv_size; - if (off < sizeof (struct GNUNET_MessageHeader)) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, + "recv"); continue; - hdr = (const struct GNUNET_MessageHeader *) buf; - msize = ntohs (hdr->size); -#if 0 - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Received message of type %u with %u bytes\n", - (unsigned int) ntohs (hdr->type), - (unsigned int) msize); -#endif - if (msize < sizeof (struct GNUNET_MessageHeader)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; } - } while (off < msize); + if (ECONNRESET != errno) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, + "recv"); + return GNUNET_SYSERR; + } + if (0 == recv_size) + { + /* regular disconnect? */ + GNUNET_break_op (0 == off); + return GNUNET_SYSERR; + } + off += recv_size; +more: + if (off < sizeof (struct GNUNET_MessageHeader)) + continue; + hdr = (const struct GNUNET_MessageHeader *) buf; + msize = ntohs (hdr->size); +#if 0 + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Received message of type %u with %u bytes\n", + (unsigned int) ntohs (hdr->type), + (unsigned int) msize); +#endif + if (msize < sizeof (struct GNUNET_MessageHeader)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + } while (off < msize); - ret = dispatch (client, - hdr); - if ( (GNUNET_OK != ret) || - (off == msize) ) - return ret; - memmove (buf, - &buf[msize], - off - msize); - off -= msize; - } + ret = dispatch (client, + hdr); + if ( (GNUNET_OK != ret) || + (off == msize) ) + return ret; + memmove (buf, + &buf[msize], + off - msize); + off -= msize; + goto more; }