Compare commits

...

17 Commits

Author SHA1 Message Date
Andreas Schneider
f17788adc2 Update ChangeLog. 2013-07-26 08:42:26 +02:00
Andreas Schneider
23e0053a41 BUG 103: Disable proxy command if set to 'none'.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-26 08:42:26 +02:00
Andreas Schneider
b6788f369e client: Fix possible NULL pointer dereference. 2013-07-26 08:42:26 +02:00
Andreas Schneider
4cc4236182 kex: Fix a double free. 2013-07-26 08:42:26 +02:00
milo
21a1c51eef Check for NULL pointers in channels.c 2013-07-26 08:42:26 +02:00
Andreas Schneider
d796de288e cmake: Set application version as package version. 2013-07-26 08:42:26 +02:00
Andreas Schneider
7ba381116d BUG 103: Fix ProxyCommand parsing. 2013-06-02 19:33:57 +02:00
Andreas Schneider
6f59c0534d config: Rename ssh_config_get_str(). 2013-06-02 19:33:57 +02:00
Andreas Schneider
494fb26b01 opts: Fix segfault in option parser. 2013-06-02 19:33:57 +02:00
Andreas Schneider
d0f9320602 cmake: Fix setting -D_FORTIFY_SOURCE=2. 2013-06-02 19:33:56 +02:00
Aris Adamantiadis
5826cb6ab2 poll: return error on poll() when pollset is empty
(cherry picked from commit 222a0d78ca)
2013-02-27 08:07:44 +01:00
Andreas Schneider
bbdef245a1 Update version number to 0.5.5. 2013-02-12 14:30:22 +01:00
Laurent Bigonville
a0d894dd2a server: Fix typo in dh_handshake_server().
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-02-05 21:16:04 +01:00
Andreas Schneider
05d8421290 Update to version 0.5.4. 2013-01-22 11:52:36 +01:00
Andreas Schneider
55b09f4264 CVE-2013-0176: Fix a remote DoS if the client doesn't send a matching kex.
Thanks to Yong Chuan Koh, X-Force Research <kohyc@sg.ibm.com>
2013-01-14 14:38:55 +01:00
Andreas Schneider
f128338132 options: Fix a free crash bug if we parse unknown options.
Thanks to Yong Chuan Koh, X-Force Research <kohyc@sg.ibm.com>
2013-01-11 08:52:27 +01:00
Andreas Schneider
ba231d0844 channels1: Fix severa possible null pointer dereferences.
(cherry picked from commit b811b89f57)
2013-01-10 13:55:12 +01:00
14 changed files with 214 additions and 51 deletions

View File

@@ -8,7 +8,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
set(APPLICATION_VERSION_MAJOR "0") set(APPLICATION_VERSION_MAJOR "0")
set(APPLICATION_VERSION_MINOR "5") set(APPLICATION_VERSION_MINOR "5")
set(APPLICATION_VERSION_PATCH "3") set(APPLICATION_VERSION_PATCH "5")
set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}") set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
@@ -19,7 +19,7 @@ set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINO
# Increment AGE. Set REVISION to 0 # Increment AGE. Set REVISION to 0
# If the source code was changed, but there were no interface changes: # If the source code was changed, but there were no interface changes:
# Increment REVISION. # Increment REVISION.
set(LIBRARY_VERSION "4.2.3") set(LIBRARY_VERSION "4.2.5")
set(LIBRARY_SOVERSION "4") set(LIBRARY_SOVERSION "4")
# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked

View File

@@ -11,9 +11,9 @@ set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
### versions ### versions
set(CPACK_PACKAGE_VERSION_MAJOR "0") set(CPACK_PACKAGE_VERSION_MAJOR "${APPLICATION_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "5") set(CPACK_PACKAGE_VERSION_MINOR "${APPLICATION_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "3") set(CPACK_PACKAGE_VERSION_PATCH "${APPLICATION_VERSION_PATCH}")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")

View File

@@ -1,6 +1,18 @@
ChangeLog ChangeLog
========== ==========
version 0.5.5 (released 2013-07-26)
* BUG 103: Fix ProxyCommand parsing.
* Fix setting -D_FORTIFY_SOURCE=2.
* Fix pollset error return if emtpy.
* Fix NULL pointer checks in channel functions.
* Several bugfixes.
version 0.5.4 (released 2013-01-22)
* CVE-2013-0176 - NULL dereference leads to denial of service
* Fixed several NULL pointer dereferences in SSHv1.
* Fixed a free crash bug in options parsing.
version 0.5.3 (released 2012-11-20) version 0.5.3 (released 2012-11-20)
* CVE-2012-4559 Fixed multiple double free() flaws. * CVE-2012-4559 Fixed multiple double free() flaws.
* CVE-2012-4560 Fixed multiple buffer overflow flaws. * CVE-2012-4560 Fixed multiple buffer overflow flaws.

View File

@@ -25,10 +25,15 @@ if (UNIX AND NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
endif (WITH_STACK_PROTECTOR) endif (WITH_STACK_PROTECTOR)
check_c_compiler_flag("-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE) if (CMAKE_BUILD_TYPE)
if (WITH_FORTIFY_SOURCE) string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2") if (NOT CMAKE_BUILD_TYPE_LOWER MATCHES debug)
endif (WITH_FORTIFY_SOURCE) check_c_compiler_flag("-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
if (WITH_FORTIFY_SOURCE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2")
endif (WITH_FORTIFY_SOURCE)
endif()
endif()
endif (${CMAKE_C_COMPILER_ID} MATCHES GNU) endif (${CMAKE_C_COMPILER_ID} MATCHES GNU)
# #

View File

@@ -79,7 +79,7 @@
/* libssh version */ /* libssh version */
#define LIBSSH_VERSION_MAJOR 0 #define LIBSSH_VERSION_MAJOR 0
#define LIBSSH_VERSION_MINOR 5 #define LIBSSH_VERSION_MINOR 5
#define LIBSSH_VERSION_MICRO 2 #define LIBSSH_VERSION_MICRO 5
#define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \ #define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \
LIBSSH_VERSION_MINOR, \ LIBSSH_VERSION_MINOR, \

View File

@@ -79,6 +79,10 @@ static ssh_channel channel_from_msg(ssh_session session, ssh_buffer packet);
ssh_channel ssh_channel_new(ssh_session session) { ssh_channel ssh_channel_new(ssh_session session) {
ssh_channel channel = NULL; ssh_channel channel = NULL;
if(session == NULL) {
return NULL;
}
channel = malloc(sizeof(struct ssh_channel_struct)); channel = malloc(sizeof(struct ssh_channel_struct));
if (channel == NULL) { if (channel == NULL) {
ssh_set_error_oom(session); ssh_set_error_oom(session);
@@ -887,6 +891,10 @@ int channel_default_bufferize(ssh_channel channel, void *data, int len,
* @see channel_request_exec() * @see channel_request_exec()
*/ */
int ssh_channel_open_session(ssh_channel channel) { int ssh_channel_open_session(ssh_channel channel) {
if(channel == NULL) {
return SSH_ERROR;
}
#ifdef WITH_SSH1 #ifdef WITH_SSH1
if (channel->session->version == 1) { if (channel->session->version == 1) {
return channel_open_session1(channel); return channel_open_session1(channel);
@@ -934,7 +942,6 @@ int ssh_channel_open_forward(ssh_channel channel, const char *remotehost,
} }
session = channel->session; session = channel->session;
enter_function(); enter_function();
if(remotehost == NULL || sourcehost == NULL) { if(remotehost == NULL || sourcehost == NULL) {
@@ -1036,9 +1043,14 @@ void ssh_channel_free(ssh_channel channel) {
* @see channel_free() * @see channel_free()
*/ */
int ssh_channel_send_eof(ssh_channel channel){ int ssh_channel_send_eof(ssh_channel channel){
ssh_session session = channel->session; ssh_session session;
int rc = SSH_ERROR; int rc = SSH_ERROR;
if(channel == NULL) {
return rc;
}
session = channel->session;
enter_function(); enter_function();
if (buffer_add_u8(session->out_buffer, SSH2_MSG_CHANNEL_EOF) < 0) { if (buffer_add_u8(session->out_buffer, SSH2_MSG_CHANNEL_EOF) < 0) {
@@ -1080,9 +1092,14 @@ error:
* @see channel_eof() * @see channel_eof()
*/ */
int ssh_channel_close(ssh_channel channel){ int ssh_channel_close(ssh_channel channel){
ssh_session session = channel->session; ssh_session session;
int rc = 0; int rc = 0;
if(channel == NULL) {
return SSH_ERROR;
}
session = channel->session;
enter_function(); enter_function();
if (channel->local_eof == 0) { if (channel->local_eof == 0) {
@@ -1143,6 +1160,10 @@ int channel_write_common(ssh_channel channel, const void *data,
return SSH_ERROR; return SSH_ERROR;
} }
if(channel == NULL || data == NULL) {
return -1;
}
session = channel->session;
enter_function(); enter_function();
if(ssh_is_blocking(session)) if(ssh_is_blocking(session))
timeout = -2; timeout = -2;
@@ -2823,11 +2844,17 @@ int ssh_channel_write_stderr(ssh_channel channel, const void *data, uint32_t len
*/ */
int ssh_channel_open_reverse_forward(ssh_channel channel, const char *remotehost, int ssh_channel_open_reverse_forward(ssh_channel channel, const char *remotehost,
int remoteport, const char *sourcehost, int localport) { int remoteport, const char *sourcehost, int localport) {
ssh_session session = channel->session; ssh_session session;
ssh_buffer payload = NULL; ssh_buffer payload = NULL;
ssh_string str = NULL; ssh_string str = NULL;
int rc = SSH_ERROR; int rc = SSH_ERROR;
if(channel == NULL) {
return rc;
}
session = channel->session;
enter_function(); enter_function();
payload = ssh_buffer_new(); payload = ssh_buffer_new();
@@ -2891,6 +2918,10 @@ int ssh_channel_request_send_exit_status(ssh_channel channel, int exit_status) {
ssh_buffer buffer = NULL; ssh_buffer buffer = NULL;
int rc = SSH_ERROR; int rc = SSH_ERROR;
if(channel == NULL) {
return SSH_ERROR;
}
#ifdef WITH_SSH1 #ifdef WITH_SSH1
if (channel->version == 1) { if (channel->version == 1) {
return SSH_ERROR; // TODO: Add support for SSH-v1 if possible. return SSH_ERROR; // TODO: Add support for SSH-v1 if possible.
@@ -2933,7 +2964,8 @@ error:
* @return SSH_OK on success, SSH_ERROR if an error occured * @return SSH_OK on success, SSH_ERROR if an error occured
* (including attempts to send signal via SSH-v1 session). * (including attempts to send signal via SSH-v1 session).
*/ */
int ssh_channel_request_send_exit_signal(ssh_channel channel, const char *sig, int core, const char *errmsg, const char *lang) { int ssh_channel_request_send_exit_signal(ssh_channel channel, const char *sig,
int core, const char *errmsg, const char *lang) {
ssh_buffer buffer = NULL; ssh_buffer buffer = NULL;
ssh_string tmp = NULL; ssh_string tmp = NULL;
int rc = SSH_ERROR; int rc = SSH_ERROR;

View File

@@ -50,11 +50,17 @@
*/ */
int channel_open_session1(ssh_channel chan) { int channel_open_session1(ssh_channel chan) {
ssh_session session;
if (chan == NULL) {
return -1;
}
session = chan->session;
/* /*
* We guess we are requesting an *exec* channel. It can only have one exec * We guess we are requesting an *exec* channel. It can only have one exec
* channel. So we abort with an error if we need more than one. * channel. So we abort with an error if we need more than one.
*/ */
ssh_session session = chan->session;
if (session->exec_channel_opened) { if (session->exec_channel_opened) {
ssh_set_error(session, SSH_REQUEST_DENIED, ssh_set_error(session, SSH_REQUEST_DENIED,
"SSH1 supports only one execution channel. " "SSH1 supports only one execution channel. "
@@ -85,8 +91,14 @@ int channel_open_session1(ssh_channel chan) {
int channel_request_pty_size1(ssh_channel channel, const char *terminal, int col, int channel_request_pty_size1(ssh_channel channel, const char *terminal, int col,
int row) { int row) {
ssh_session session = channel->session; ssh_session session;
ssh_string str = NULL; ssh_string str = NULL;
if (channel == NULL) {
return SSH_ERROR;
}
session = channel->session;
if(channel->request_state != SSH_CHANNEL_REQ_STATE_NONE){ if(channel->request_state != SSH_CHANNEL_REQ_STATE_NONE){
ssh_set_error(session,SSH_REQUEST_DENIED,"Wrong request state"); ssh_set_error(session,SSH_REQUEST_DENIED,"Wrong request state");
return SSH_ERROR; return SSH_ERROR;
@@ -139,7 +151,13 @@ int channel_request_pty_size1(ssh_channel channel, const char *terminal, int col
} }
int channel_change_pty_size1(ssh_channel channel, int cols, int rows) { int channel_change_pty_size1(ssh_channel channel, int cols, int rows) {
ssh_session session = channel->session; ssh_session session;
if (channel == NULL) {
return SSH_ERROR;
}
session = channel->session;
if(channel->request_state != SSH_CHANNEL_REQ_STATE_NONE){ if(channel->request_state != SSH_CHANNEL_REQ_STATE_NONE){
ssh_set_error(session,SSH_REQUEST_DENIED,"Wrong request state"); ssh_set_error(session,SSH_REQUEST_DENIED,"Wrong request state");
return SSH_ERROR; return SSH_ERROR;
@@ -182,7 +200,12 @@ int channel_change_pty_size1(ssh_channel channel, int cols, int rows) {
} }
int channel_request_shell1(ssh_channel channel) { int channel_request_shell1(ssh_channel channel) {
ssh_session session = channel->session; ssh_session session;
if (channel == NULL) {
return -1;
}
session = channel->session;
if (buffer_add_u8(session->out_buffer,SSH_CMSG_EXEC_SHELL) < 0) { if (buffer_add_u8(session->out_buffer,SSH_CMSG_EXEC_SHELL) < 0) {
return -1; return -1;
@@ -198,9 +221,14 @@ int channel_request_shell1(ssh_channel channel) {
} }
int channel_request_exec1(ssh_channel channel, const char *cmd) { int channel_request_exec1(ssh_channel channel, const char *cmd) {
ssh_session session = channel->session; ssh_session session;
ssh_string command = NULL; ssh_string command = NULL;
if (channel == NULL) {
return -1;
}
session = channel->session;
command = ssh_string_from_char(cmd); command = ssh_string_from_char(cmd);
if (command == NULL) { if (command == NULL) {
return -1; return -1;
@@ -227,6 +255,11 @@ SSH_PACKET_CALLBACK(ssh_packet_data1){
ssh_string str = NULL; ssh_string str = NULL;
int is_stderr=(type==SSH_SMSG_STDOUT_DATA ? 0 : 1); int is_stderr=(type==SSH_SMSG_STDOUT_DATA ? 0 : 1);
(void)user; (void)user;
if (channel == NULL) {
return SSH_PACKET_NOT_USED;
}
str = buffer_get_ssh_string(packet); str = buffer_get_ssh_string(packet);
if (str == NULL) { if (str == NULL) {
ssh_log(session, SSH_LOG_FUNCTIONS, "Invalid data packet !\n"); ssh_log(session, SSH_LOG_FUNCTIONS, "Invalid data packet !\n");
@@ -254,6 +287,10 @@ SSH_PACKET_CALLBACK(ssh_packet_close1){
(void)type; (void)type;
(void)user; (void)user;
if (channel == NULL) {
return SSH_PACKET_NOT_USED;
}
buffer_get_u32(packet, &status); buffer_get_u32(packet, &status);
/* /*
* It's much more than a channel closing. spec says it's the last * It's much more than a channel closing. spec says it's the last
@@ -275,6 +312,11 @@ SSH_PACKET_CALLBACK(ssh_packet_exist_status1){
uint32_t status; uint32_t status;
(void)type; (void)type;
(void)user; (void)user;
if (channel == NULL) {
return SSH_PACKET_NOT_USED;
}
buffer_get_u32(packet, &status); buffer_get_u32(packet, &status);
channel->state = SSH_CHANNEL_STATE_CLOSED; channel->state = SSH_CHANNEL_STATE_CLOSED;
channel->remote_eof = 1; channel->remote_eof = 1;
@@ -285,10 +327,16 @@ SSH_PACKET_CALLBACK(ssh_packet_exist_status1){
int channel_write1(ssh_channel channel, const void *data, int len) { int channel_write1(ssh_channel channel, const void *data, int len) {
ssh_session session = channel->session; ssh_session session;
int origlen = len; int origlen = len;
int effectivelen; int effectivelen;
const unsigned char *ptr=data; const unsigned char *ptr=data;
if (channel == NULL) {
return -1;
}
session = channel->session;
while (len > 0) { while (len > 0) {
if (buffer_add_u8(session->out_buffer, SSH_CMSG_STDIN_DATA) < 0) { if (buffer_add_u8(session->out_buffer, SSH_CMSG_STDIN_DATA) < 0) {
return -1; return -1;
@@ -314,6 +362,11 @@ int channel_write1(ssh_channel channel, const void *data, int len) {
ssh_channel ssh_get_channel1(ssh_session session){ ssh_channel ssh_get_channel1(ssh_session session){
struct ssh_iterator *it; struct ssh_iterator *it;
if (session == NULL) {
return NULL;
}
/* With SSH1, the channel is always the first one */ /* With SSH1, the channel is always the first one */
if(session->channels != NULL){ if(session->channels != NULL){
it = ssh_list_get_iterator(session->channels); it = ssh_list_get_iterator(session->channels);

View File

@@ -765,7 +765,7 @@ void ssh_disconnect(ssh_session session) {
enter_function(); enter_function();
if (ssh_socket_is_open(session->socket)) { if (session->socket != NULL && ssh_socket_is_open(session->socket)) {
if (buffer_add_u8(session->out_buffer, SSH2_MSG_DISCONNECT) < 0) { if (buffer_add_u8(session->out_buffer, SSH2_MSG_DISCONNECT) < 0) {
goto error; goto error;
} }
@@ -790,7 +790,7 @@ void ssh_disconnect(ssh_session session) {
} }
error: error:
session->alive = 0; session->alive = 0;
if(session->socket){ if (session->socket != NULL){
ssh_socket_reset(session->socket); ssh_socket_reset(session->socket);
} }
session->fd = SSH_INVALID_SOCKET; session->fd = SSH_INVALID_SOCKET;

View File

@@ -78,7 +78,7 @@ static enum ssh_config_opcode_e ssh_config_get_opcode(char *keyword) {
return SOC_UNSUPPORTED; return SOC_UNSUPPORTED;
} }
static char *ssh_config_get_token(char **str) { static char *ssh_config_get_cmd(char **str) {
register char *c; register char *c;
char *r; char *r;
@@ -98,6 +98,25 @@ static char *ssh_config_get_token(char **str) {
} }
} }
for (r = c; *c; c++) {
if (*c == '\n') {
*c = '\0';
goto out;
}
}
out:
*str = c + 1;
return r;
}
static char *ssh_config_get_token(char **str) {
register char *c;
char *r;
c = ssh_config_get_cmd(str);
for (r = c; *c; c++) { for (r = c; *c; c++) {
if (isblank(*c)) { if (isblank(*c)) {
*c = '\0'; *c = '\0';
@@ -127,7 +146,7 @@ static int ssh_config_get_int(char **str, int notfound) {
return notfound; return notfound;
} }
static const char *ssh_config_get_str(char **str, const char *def) { static const char *ssh_config_get_str_tok(char **str, const char *def) {
char *p; char *p;
p = ssh_config_get_token(str); p = ssh_config_get_token(str);
@@ -141,7 +160,7 @@ static const char *ssh_config_get_str(char **str, const char *def) {
static int ssh_config_get_yesno(char **str, int notfound) { static int ssh_config_get_yesno(char **str, int notfound) {
const char *p; const char *p;
p = ssh_config_get_str(str, NULL); p = ssh_config_get_str_tok(str, NULL);
if (p == NULL) { if (p == NULL) {
return notfound; return notfound;
} }
@@ -192,8 +211,8 @@ static int ssh_config_parse_line(ssh_session session, const char *line,
case SOC_HOST: case SOC_HOST:
*parsing = 0; *parsing = 0;
lowerhost = (session->host) ? ssh_lowercase(session->host) : NULL; lowerhost = (session->host) ? ssh_lowercase(session->host) : NULL;
for (p = ssh_config_get_str(&s, NULL); p && *p; for (p = ssh_config_get_str_tok(&s, NULL); p && *p;
p = ssh_config_get_str(&s, NULL)) { p = ssh_config_get_str_tok(&s, NULL)) {
if (match_hostname(lowerhost, p, strlen(p))) { if (match_hostname(lowerhost, p, strlen(p))) {
*parsing = 1; *parsing = 1;
} }
@@ -201,14 +220,14 @@ static int ssh_config_parse_line(ssh_session session, const char *line,
SAFE_FREE(lowerhost); SAFE_FREE(lowerhost);
break; break;
case SOC_HOSTNAME: case SOC_HOSTNAME:
p = ssh_config_get_str(&s, NULL); p = ssh_config_get_str_tok(&s, NULL);
if (p && *parsing) { if (p && *parsing) {
ssh_options_set(session, SSH_OPTIONS_HOST, p); ssh_options_set(session, SSH_OPTIONS_HOST, p);
} }
break; break;
case SOC_PORT: case SOC_PORT:
if (session->port == 22) { if (session->port == 22) {
p = ssh_config_get_str(&s, NULL); p = ssh_config_get_str_tok(&s, NULL);
if (p && *parsing) { if (p && *parsing) {
ssh_options_set(session, SSH_OPTIONS_PORT_STR, p); ssh_options_set(session, SSH_OPTIONS_PORT_STR, p);
} }
@@ -216,20 +235,20 @@ static int ssh_config_parse_line(ssh_session session, const char *line,
break; break;
case SOC_USERNAME: case SOC_USERNAME:
if (session->username == NULL) { if (session->username == NULL) {
p = ssh_config_get_str(&s, NULL); p = ssh_config_get_str_tok(&s, NULL);
if (p && *parsing) { if (p && *parsing) {
ssh_options_set(session, SSH_OPTIONS_USER, p); ssh_options_set(session, SSH_OPTIONS_USER, p);
} }
} }
break; break;
case SOC_IDENTITY: case SOC_IDENTITY:
p = ssh_config_get_str(&s, NULL); p = ssh_config_get_str_tok(&s, NULL);
if (p && *parsing) { if (p && *parsing) {
ssh_options_set(session, SSH_OPTIONS_ADD_IDENTITY, p); ssh_options_set(session, SSH_OPTIONS_ADD_IDENTITY, p);
} }
break; break;
case SOC_CIPHERS: case SOC_CIPHERS:
p = ssh_config_get_str(&s, NULL); p = ssh_config_get_str_tok(&s, NULL);
if (p && *parsing) { if (p && *parsing) {
ssh_options_set(session, SSH_OPTIONS_CIPHERS_C_S, p); ssh_options_set(session, SSH_OPTIONS_CIPHERS_C_S, p);
ssh_options_set(session, SSH_OPTIONS_CIPHERS_S_C, p); ssh_options_set(session, SSH_OPTIONS_CIPHERS_S_C, p);
@@ -246,7 +265,7 @@ static int ssh_config_parse_line(ssh_session session, const char *line,
} }
break; break;
case SOC_PROTOCOL: case SOC_PROTOCOL:
p = ssh_config_get_str(&s, NULL); p = ssh_config_get_str_tok(&s, NULL);
if (p && *parsing) { if (p && *parsing) {
char *a, *b; char *a, *b;
b = strdup(p); b = strdup(p);
@@ -289,13 +308,13 @@ static int ssh_config_parse_line(ssh_session session, const char *line,
} }
break; break;
case SOC_KNOWNHOSTS: case SOC_KNOWNHOSTS:
p = ssh_config_get_str(&s, NULL); p = ssh_config_get_str_tok(&s, NULL);
if (p && *parsing) { if (p && *parsing) {
ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, p); ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, p);
} }
break; break;
case SOC_PROXYCOMMAND: case SOC_PROXYCOMMAND:
p = ssh_config_get_str(&s, NULL); p = ssh_config_get_cmd(&s);
if (p && *parsing) { if (p && *parsing) {
ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, p); ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, p);
} }

View File

@@ -432,6 +432,7 @@ int ssh_send_kex(ssh_session session, int server_kex) {
goto error; goto error;
} }
ssh_string_free(str); ssh_string_free(str);
str = NULL;
} }
if (buffer_add_u8(session->out_buffer, 0) < 0) { if (buffer_add_u8(session->out_buffer, 0) < 0) {

View File

@@ -655,11 +655,15 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type,
return -1; return -1;
} else { } else {
SAFE_FREE(session->ProxyCommand); SAFE_FREE(session->ProxyCommand);
q = strdup(value); /* Setting the command to 'none' disables this option. */
if (q == NULL) { rc = strcasecmp(value, "none");
return -1; if (rc != 0) {
q = strdup(value);
if (q == NULL) {
return -1;
}
session->ProxyCommand = q;
} }
session->ProxyCommand = q;
} }
break; break;
default: default:
@@ -698,7 +702,7 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv) {
char *cipher = NULL; char *cipher = NULL;
char *identity = NULL; char *identity = NULL;
char *port = NULL; char *port = NULL;
char **save = NULL; char **save = NULL, **tmp;
int i = 0; int i = 0;
int argc = *argcptr; int argc = *argcptr;
int debuglevel = 0; int debuglevel = 0;
@@ -720,12 +724,6 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv) {
int saveoptind = optind; /* need to save 'em */ int saveoptind = optind; /* need to save 'em */
int saveopterr = opterr; int saveopterr = opterr;
save = malloc(argc * sizeof(char *));
if (save == NULL) {
ssh_set_error_oom(session);
return -1;
}
opterr = 0; /* shut up getopt */ opterr = 0; /* shut up getopt */
while(cont && ((i = getopt(argc, argv, "c:i:Cl:p:vb:rd12")) != -1)) { while(cont && ((i = getopt(argc, argv, "c:i:Cl:p:vb:rd12")) != -1)) {
switch(i) { switch(i) {
@@ -765,6 +763,13 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv) {
{ {
char opt[3]="- "; char opt[3]="- ";
opt[1] = optopt; opt[1] = optopt;
tmp = realloc(save, (current + 1) * sizeof(char*));
if (tmp == NULL) {
SAFE_FREE(save);
ssh_set_error_oom(session);
return -1;
}
save = tmp;
save[current] = strdup(opt); save[current] = strdup(opt);
if (save[current] == NULL) { if (save[current] == NULL) {
SAFE_FREE(save); SAFE_FREE(save);
@@ -780,7 +785,16 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv) {
} /* while */ } /* while */
opterr = saveopterr; opterr = saveopterr;
while (optind < argc) { while (optind < argc) {
save[current++] = argv[optind++]; tmp = realloc(save, (current + 1) * sizeof(char*));
if (tmp == NULL) {
SAFE_FREE(save);
ssh_set_error_oom(session);
return -1;
}
save = tmp;
save[current] = argv[optind];
current++;
optind++;
} }
if (usersa && usedss) { if (usersa && usedss) {

View File

@@ -581,7 +581,7 @@ int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout) {
int revents; int revents;
if (!ctx->polls_used) if (!ctx->polls_used)
return 0; return SSH_ERROR;
rc = ssh_poll(ctx->pollfds, ctx->polls_used, timeout); rc = ssh_poll(ctx->pollfds, ctx->polls_used, timeout);
if(rc < 0) if(rc < 0)

View File

@@ -184,7 +184,11 @@ static int dh_handshake_server(ssh_session session) {
prv = session->rsa_key; prv = session->rsa_key;
break; break;
default: default:
prv = NULL; ssh_set_error(session,
SSH_FATAL,
"Could not determine the specified hostkey");
ssh_string_free(f);
return -1;
} }
pub = publickey_from_privatekey(prv); pub = publickey_from_privatekey(prv);
@@ -270,6 +274,8 @@ static int dh_handshake_server(ssh_session session) {
*/ */
static void ssh_server_connection_callback(ssh_session session){ static void ssh_server_connection_callback(ssh_session session){
int ssh1,ssh2; int ssh1,ssh2;
int rc;
enter_function(); enter_function();
switch(session->session_state){ switch(session->session_state){
case SSH_SESSION_STATE_NONE: case SSH_SESSION_STATE_NONE:
@@ -338,7 +344,10 @@ static void ssh_server_connection_callback(ssh_session session){
case SSH_SESSION_STATE_KEXINIT_RECEIVED: case SSH_SESSION_STATE_KEXINIT_RECEIVED:
set_status(session,0.6f); set_status(session,0.6f);
ssh_list_kex(session, &session->client_kex); // log client kex ssh_list_kex(session, &session->client_kex); // log client kex
crypt_set_algorithms_server(session); rc = crypt_set_algorithms_server(session);
if (rc == SSH_ERROR) {
goto error;
}
if (set_kex(session) < 0) { if (set_kex(session) < 0) {
goto error; goto error;
} }

View File

@@ -119,6 +119,23 @@ static void torture_options_set_identity(void **state) {
assert_string_equal(session->identity->root->next->data, "identity1"); assert_string_equal(session->identity->root->next->data, "identity1");
} }
static void torture_options_proxycommand(void **state) {
ssh_session session = *state;
int rc;
/* Enable ProxyCommand */
rc = ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, "ssh -q -A -X -W %h:%p JUMPHOST");
assert_int_equal(rc, 0);
assert_string_equal(session->ProxyCommand, "ssh -q -A -X -W %h:%p JUMPHOST");
/* Disable ProxyCommand */
rc = ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, "none");
assert_int_equal(rc, 0);
assert_true(session->ProxyCommand == NULL);
}
int torture_run_tests(void) { int torture_run_tests(void) {
int rc; int rc;
const UnitTest tests[] = { const UnitTest tests[] = {
@@ -127,6 +144,7 @@ int torture_run_tests(void) {
unit_test_setup_teardown(torture_options_set_fd, setup, teardown), unit_test_setup_teardown(torture_options_set_fd, setup, teardown),
unit_test_setup_teardown(torture_options_set_user, setup, teardown), unit_test_setup_teardown(torture_options_set_user, setup, teardown),
unit_test_setup_teardown(torture_options_set_identity, setup, teardown), unit_test_setup_teardown(torture_options_set_identity, setup, teardown),
unit_test_setup_teardown(torture_options_proxycommand, setup, teardown),
}; };
ssh_init(); ssh_init();