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 <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Jakub Jelen
2025-01-14 14:43:22 +01:00
parent e795849299
commit 0cd749a533
4 changed files with 28 additions and 14 deletions

View File

@@ -91,6 +91,7 @@ set(libssh_SRCS
ecdh.c ecdh.c
error.c error.c
getpass.c getpass.c
gzip.c
init.c init.c
kdf.c kdf.c
kex.c kex.c
@@ -252,13 +253,6 @@ if (WITH_GEX)
) )
endif (WITH_GEX) endif (WITH_GEX)
if (WITH_ZLIB)
set(libssh_SRCS
${libssh_SRCS}
gzip.c
)
endif(WITH_ZLIB)
if (WITH_GSSAPI AND GSSAPI_FOUND) if (WITH_GSSAPI AND GSSAPI_FOUND)
set(libssh_SRCS set(libssh_SRCS
${libssh_SRCS} ${libssh_SRCS}

View File

@@ -26,13 +26,15 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <zlib.h>
#include "libssh/buffer.h" #include "libssh/buffer.h"
#include "libssh/crypto.h" #include "libssh/crypto.h"
#include "libssh/priv.h" #include "libssh/priv.h"
#include "libssh/session.h" #include "libssh/session.h"
#ifdef WITH_ZLIB
#include <zlib.h>
#ifndef BLOCKSIZE #ifndef BLOCKSIZE
#define BLOCKSIZE 4092 #define BLOCKSIZE 4092
#endif #endif
@@ -274,3 +276,27 @@ compress_cleanup(struct ssh_crypto_struct *crypto)
} }
SAFE_FREE(crypto->compress_in_ctx); 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 */

View File

@@ -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); ssh_buffer_pass_bytes_end(session->in_buffer, padding);
compsize = ssh_buffer_get_len(session->in_buffer); compsize = ssh_buffer_get_len(session->in_buffer);
#ifdef WITH_ZLIB
if (crypto && crypto->do_compress_in && if (crypto && crypto->do_compress_in &&
ssh_buffer_get_len(session->in_buffer) > 0) { ssh_buffer_get_len(session->in_buffer) > 0) {
rc = decompress_buffer(session, session->in_buffer, 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; goto error;
} }
} }
#endif /* WITH_ZLIB */
payloadsize = ssh_buffer_get_len(session->in_buffer); payloadsize = ssh_buffer_get_len(session->in_buffer);
if (session->recv_seq == UINT32_MAX) { if (session->recv_seq == UINT32_MAX) {
/* Overflowing sequence numbers is always fishy */ /* Overflowing sequence numbers is always fishy */
@@ -1706,7 +1704,6 @@ static int packet_send2(ssh_session session)
lenfield_blocksize = 0; lenfield_blocksize = 0;
} }
#ifdef WITH_ZLIB
if (crypto != NULL && crypto->do_compress_out && if (crypto != NULL && crypto->do_compress_out &&
ssh_buffer_get_len(session->out_buffer) > 0) { ssh_buffer_get_len(session->out_buffer) > 0) {
rc = compress_buffer(session,session->out_buffer); 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); currentlen = ssh_buffer_get_len(session->out_buffer);
} }
#endif /* WITH_ZLIB */
compsize = currentlen; compsize = currentlen;
/* compressed payload + packet len (4) + padding_size len (1) */ /* compressed payload + packet len (4) + padding_size len (1) */
/* totallen - lenfield_blocksize - etm_packet_offset must be equal to 0 (mod blocksize) */ /* totallen - lenfield_blocksize - etm_packet_offset must be equal to 0 (mod blocksize) */

View File

@@ -197,9 +197,7 @@ void crypto_free(struct ssh_crypto_struct *crypto)
explicit_bzero(crypto->secret_hash, crypto->digest_len); explicit_bzero(crypto->secret_hash, crypto->digest_len);
SAFE_FREE(crypto->secret_hash); SAFE_FREE(crypto->secret_hash);
} }
#ifdef WITH_ZLIB
compress_cleanup(crypto); compress_cleanup(crypto);
#endif /* WITH_ZLIB */
SAFE_FREE(crypto->encryptIV); SAFE_FREE(crypto->encryptIV);
SAFE_FREE(crypto->decryptIV); SAFE_FREE(crypto->decryptIV);
SAFE_FREE(crypto->encryptMAC); SAFE_FREE(crypto->encryptMAC);