From 006666c007b3cf2ddbb8e6720c087dc7a38fae45 Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Tue, 19 Dec 2023 11:07:35 -0700 Subject: [PATCH 1/2] style: grammar fixes and clarifications, and trivial newline --- libcperciva/crypto/crypto_entropy.c | 3 ++- libcperciva/events/events_network.c | 8 ++++---- libcperciva/util/sock.c | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libcperciva/crypto/crypto_entropy.c b/libcperciva/crypto/crypto_entropy.c index c9023c2c..936e22ae 100644 --- a/libcperciva/crypto/crypto_entropy.c +++ b/libcperciva/crypto/crypto_entropy.c @@ -41,7 +41,8 @@ static void generate(uint8_t *, size_t); #ifdef CPUSUPPORT_X86_RDRAND static void -update_from_rdrand(void) { +update_from_rdrand(void) +{ unsigned int buf[8]; /* This is only *extra* entropy, so it's ok if it fails. */ diff --git a/libcperciva/events/events_network.c b/libcperciva/events/events_network.c index c81338f8..73d6aa79 100644 --- a/libcperciva/events/events_network.c +++ b/libcperciva/events/events_network.c @@ -22,8 +22,8 @@ * for it to be larger than size_t unless there's an undocumented limit on * the number of descriptors which can be polled (since poll takes an array, * the size of which must fit into a size_t); and nfds_t should be able to - * the value INT_MAX + 1 (in case every possible file descriptor is in use - * and being polled for). + * store the value INT_MAX + 1 (in case every possible file descriptor is in + * use and being polled for). */ CTASSERT((nfds_t)(-1) <= (size_t)(-1)); CTASSERT((nfds_t)((size_t)(INT_MAX) + 1) == (size_t)(INT_MAX) + 1); @@ -65,7 +65,7 @@ static size_t fdscanpos; * S[i].reader != NULL <==> (fds[S[i].pollpos].events & POLLIN) != 0 * S[i].writer != NULL <==> (fds[S[i].pollpos].events & POLLOUT) != 0 * 5. We don't have events ready which we don't want: - * (fds[j].revents & (POLLIN | POLLOUT) & (~fds[j].events])) == 0 + * (fds[j].revents & (POLLIN | POLLOUT) & (~fds[j].events)) == 0 * 6. Returned events are in position to be scanned later: * fds[j].revents != 0 ==> f < fdscanpos. */ @@ -451,7 +451,7 @@ events_network_get(void) break; } - /* Are we ready for reading? */ + /* Are we ready for writing? */ if (fds[fdscanpos].revents & POLLOUT) { r = socketlist_get(S, (size_t)fds[fdscanpos].fd)->writer; diff --git a/libcperciva/util/sock.c b/libcperciva/util/sock.c index ce4da55a..fa6eadf7 100644 --- a/libcperciva/util/sock.c +++ b/libcperciva/util/sock.c @@ -34,6 +34,8 @@ sock_resolve_unix(const char * addr) if ((sa_un = calloc(1, sizeof(struct sockaddr_un))) == NULL) goto err0; sa_un->sun_family = AF_UNIX; + + /* Safely copy addr into the structure. */ if (strlen(addr) >= sizeof(sa_un->sun_path)) { warn0("socket path too long: %s", addr); goto err1; From c3b3b7e72c8a092892220d7442c29e510bd801fa Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Tue, 19 Dec 2023 10:07:36 -0800 Subject: [PATCH 2/2] style: fix spelling, and argument names crypto_compat.c spelling fix for: 2023-10-14 crypto_compat_free(): handle recent OpenSSL and LibreSSL e5df014fa68d2e0d9b6d10b589c5e81e3430671e Some mismatches between argument names in the declarations and definitions: tsnetwork.c, introduced in: 2008-04-25 Tarsnap 1.0.0 41f175dbc884f04e36a98811188e1100bb4dbfae crypto_compat.c, introduced in: 2017-03-13 crypto_compat: begin, add crypto_compat_RSA_valid_size() d06e4043756f390fe72ae2acc67bd2e98a5aeb91 The header files uses `key`, as do all the other functions in this file. Reported by: clang-tidy --- lib/crypto/crypto_compat.c | 16 ++++++++-------- lib/crypto/crypto_compat.h | 4 ++-- lib/network/tsnetwork_buf.c | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/crypto/crypto_compat.c b/lib/crypto/crypto_compat.c index 52209a19..f9769604 100644 --- a/lib/crypto/crypto_compat.c +++ b/lib/crypto/crypto_compat.c @@ -34,21 +34,21 @@ #endif /* LIBRESSL_VERSION_NUMBER */ /** - * crypto_compat_RSA_valid_size(rsa): - * Return nonzero if ${rsa} has a valid size, and zero for an invalid size. + * crypto_compat_RSA_valid_size(key): + * Return nonzero if ${key} has a valid size, and zero for an invalid size. */ int -crypto_compat_RSA_valid_size(const RSA * const rsa) +crypto_compat_RSA_valid_size(const RSA * const key) { /* Sanity checks. */ - assert(rsa != NULL); + assert(key != NULL); #if OPENSSL_VERSION_NUMBER < 0x10100000L - assert(rsa->n != NULL); - return ((RSA_size(rsa) == 256) && (BN_num_bits(rsa->n) == 2048)); + assert(key->n != NULL); + return ((RSA_size(key) == 256) && (BN_num_bits(key->n) == 2048)); #else - return ((RSA_size(rsa) == 256) && (RSA_bits(rsa) == 2048)); + return ((RSA_size(key) == 256) && (RSA_bits(key) == 2048)); #endif } @@ -255,7 +255,7 @@ crypto_compat_free(void) OPENSSL_cleanup(); CRYPTO_cleanup_all_ex_data(); #else - /* Easerlier versions of OpenSSL and LibreSSL. */ + /* Earlier versions of OpenSSL and LibreSSL. */ /* Free OpenSSL error queue. */ #if OPENSSL_VERSION_NUMBER < 0x10000000L diff --git a/lib/crypto/crypto_compat.h b/lib/crypto/crypto_compat.h index f28169d3..669d863b 100644 --- a/lib/crypto/crypto_compat.h +++ b/lib/crypto/crypto_compat.h @@ -4,8 +4,8 @@ #include /** - * crypto_compat_RSA_valid_size(rsa): - * Return nonzero if ${rsa} has a valid size, and zero for an invalid size. + * crypto_compat_RSA_valid_size(key): + * Return nonzero if ${key} has a valid size, and zero for an invalid size. */ int crypto_compat_RSA_valid_size(const RSA * const key); diff --git a/lib/network/tsnetwork_buf.c b/lib/network/tsnetwork_buf.c index da405d49..a246b0e3 100644 --- a/lib/network/tsnetwork_buf.c +++ b/lib/network/tsnetwork_buf.c @@ -43,7 +43,7 @@ struct network_buf_cookie { int flags; }; -static int callback_buf(void * cookie, int timedout); +static int callback_buf(void * cookie, int status); static int network_buf(int fd, uint8_t * buf, size_t buflen, struct timeval * to0, struct timeval * to1, network_callback * callback, void * cookie,