diff --git a/src/bind_config.c b/src/bind_config.c index 14b84db0..ace5a0ac 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -40,7 +40,9 @@ #include "libssh/server.h" #include "libssh/options.h" +#ifndef MAX_LINE_SIZE #define MAX_LINE_SIZE 1024 +#endif /* Flags used for the parser state */ #define PARSING 1 diff --git a/src/config.c b/src/config.c index 599d6f80..a082e994 100644 --- a/src/config.c +++ b/src/config.c @@ -48,7 +48,9 @@ #include "libssh/misc.h" #include "libssh/options.h" +#ifndef MAX_LINE_SIZE #define MAX_LINE_SIZE 1024 +#endif struct ssh_config_keyword_table_s { const char *name; diff --git a/src/known_hosts.c b/src/known_hosts.c index ec6da308..3feab159 100644 --- a/src/known_hosts.c +++ b/src/known_hosts.c @@ -45,6 +45,10 @@ # include #endif +#ifndef MAX_LINE_SIZE +#define MAX_LINE_SIZE 4096 +#endif + /** * @addtogroup libssh_session * @@ -74,7 +78,7 @@ static struct ssh_tokens_st *ssh_get_knownhost_line(FILE **file, const char *filename, const char **found_type) { - char buffer[4096] = {0}; + char buffer[MAX_LINE_SIZE] = {0}; char *ptr; struct ssh_tokens_st *tokens; @@ -431,7 +435,6 @@ char * ssh_dump_knownhost(ssh_session session) { ssh_key server_pubkey = NULL; char *host; char *hostport; - size_t len = 4096; char *buffer; char *b64_key; int rc; @@ -467,7 +470,7 @@ char * ssh_dump_knownhost(ssh_session session) { return NULL; } - buffer = calloc (1, 4096); + buffer = calloc (1, MAX_LINE_SIZE); if (!buffer) { SAFE_FREE(host); return NULL; @@ -480,7 +483,7 @@ char * ssh_dump_knownhost(ssh_session session) { return NULL; } - snprintf(buffer, len, + snprintf(buffer, MAX_LINE_SIZE, "%s %s %s\n", host, server_pubkey->type_c, diff --git a/src/knownhosts.c b/src/knownhosts.c index f2ef088c..ad36363e 100644 --- a/src/knownhosts.c +++ b/src/knownhosts.c @@ -44,6 +44,10 @@ #include "libssh/knownhosts.h" #include "libssh/token.h" +#ifndef MAX_LINE_SIZE +#define MAX_LINE_SIZE 8192 +#endif + /** * @addtogroup libssh_session * @@ -216,7 +220,7 @@ static int ssh_known_hosts_read_entries(const char *match, const char *filename, struct ssh_list **entries) { - char line[8192]; + char line[MAX_LINE_SIZE]; size_t lineno = 0; size_t len = 0; FILE *fp; @@ -895,7 +899,7 @@ int ssh_session_export_known_hosts_entry(ssh_session session, { ssh_key server_pubkey = NULL; char *host = NULL; - char entry_buf[4096] = {0}; + char entry_buf[MAX_LINE_SIZE] = {0}; char *b64_key = NULL; int rc; diff --git a/src/pki.c b/src/pki.c index 9248c9b3..5d57ca71 100644 --- a/src/pki.c +++ b/src/pki.c @@ -67,6 +67,10 @@ #include "libssh/misc.h" #include "libssh/agent.h" +#ifndef MAX_LINE_SIZE +#define MAX_LINE_SIZE 4096 +#endif + #define PKCS11_URI "pkcs11:" enum ssh_keytypes_e pki_privatekey_type_from_string(const char *privkey) @@ -2094,7 +2098,7 @@ int ssh_pki_export_pubkey_base64(const ssh_key key, int ssh_pki_export_pubkey_file(const ssh_key key, const char *filename) { - char key_buf[4096]; + char key_buf[MAX_LINE_SIZE]; char host[256]; char *b64_key; char *user;