From 0cd749a533c911cebae583c2be24f126f5e4a884 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Tue, 14 Jan 2025 14:43:22 +0100 Subject: [PATCH] zlib: Move conditional compilation inside of the gzip.c This implements stub for the compression functions and includes the gzip.c in the compilation target uncoditionally, keeping the WITH_ZLIB conditional compilation only in the gzip.c Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider --- src/CMakeLists.txt | 8 +------- src/gzip.c | 28 +++++++++++++++++++++++++++- src/packet.c | 4 ---- src/wrapper.c | 2 -- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9096cbce..e0243bb0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -91,6 +91,7 @@ set(libssh_SRCS ecdh.c error.c getpass.c + gzip.c init.c kdf.c kex.c @@ -252,13 +253,6 @@ if (WITH_GEX) ) endif (WITH_GEX) -if (WITH_ZLIB) - set(libssh_SRCS - ${libssh_SRCS} - gzip.c - ) -endif(WITH_ZLIB) - if (WITH_GSSAPI AND GSSAPI_FOUND) set(libssh_SRCS ${libssh_SRCS} diff --git a/src/gzip.c b/src/gzip.c index 27c8042b..e814080a 100644 --- a/src/gzip.c +++ b/src/gzip.c @@ -26,13 +26,15 @@ #include #include -#include #include "libssh/buffer.h" #include "libssh/crypto.h" #include "libssh/priv.h" #include "libssh/session.h" +#ifdef WITH_ZLIB +#include + #ifndef BLOCKSIZE #define BLOCKSIZE 4092 #endif @@ -274,3 +276,27 @@ compress_cleanup(struct ssh_crypto_struct *crypto) } SAFE_FREE(crypto->compress_in_ctx); } +#else /* WITH_ZLIB */ + +int +compress_buffer(UNUSED_PARAM(ssh_session session), UNUSED_PARAM(ssh_buffer buf)) +{ + /* without zlib compiled in, this should never happen */ + return -1; +} +int +decompress_buffer(UNUSED_PARAM(ssh_session session), + UNUSED_PARAM(ssh_buffer buf), + UNUSED_PARAM(size_t maxlen)) +{ + /* without zlib compiled in, this should never happen */ + return -1; +} + +void +compress_cleanup(UNUSED_PARAM(struct ssh_crypto_struct *crypto)) +{ + /* no-op */ +} + +#endif /* WITH_ZLIB */ diff --git a/src/packet.c b/src/packet.c index 42b9f9a7..2614f60b 100644 --- a/src/packet.c +++ b/src/packet.c @@ -1303,7 +1303,6 @@ ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user) ssh_buffer_pass_bytes_end(session->in_buffer, padding); compsize = ssh_buffer_get_len(session->in_buffer); -#ifdef WITH_ZLIB if (crypto && crypto->do_compress_in && ssh_buffer_get_len(session->in_buffer) > 0) { rc = decompress_buffer(session, session->in_buffer, @@ -1312,7 +1311,6 @@ ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user) goto error; } } -#endif /* WITH_ZLIB */ payloadsize = ssh_buffer_get_len(session->in_buffer); if (session->recv_seq == UINT32_MAX) { /* Overflowing sequence numbers is always fishy */ @@ -1706,7 +1704,6 @@ static int packet_send2(ssh_session session) lenfield_blocksize = 0; } -#ifdef WITH_ZLIB if (crypto != NULL && crypto->do_compress_out && ssh_buffer_get_len(session->out_buffer) > 0) { rc = compress_buffer(session,session->out_buffer); @@ -1715,7 +1712,6 @@ static int packet_send2(ssh_session session) } currentlen = ssh_buffer_get_len(session->out_buffer); } -#endif /* WITH_ZLIB */ compsize = currentlen; /* compressed payload + packet len (4) + padding_size len (1) */ /* totallen - lenfield_blocksize - etm_packet_offset must be equal to 0 (mod blocksize) */ diff --git a/src/wrapper.c b/src/wrapper.c index e3a71622..55fa0ca4 100644 --- a/src/wrapper.c +++ b/src/wrapper.c @@ -197,9 +197,7 @@ void crypto_free(struct ssh_crypto_struct *crypto) explicit_bzero(crypto->secret_hash, crypto->digest_len); SAFE_FREE(crypto->secret_hash); } -#ifdef WITH_ZLIB compress_cleanup(crypto); -#endif /* WITH_ZLIB */ SAFE_FREE(crypto->encryptIV); SAFE_FREE(crypto->decryptIV); SAFE_FREE(crypto->encryptMAC);