diff options
| author | milo <milo@r0ot.me> | 2011-02-14 20:02:02 +0100 |
|---|---|---|
| committer | Andreas Schneider <asn@cryptomilk.org> | 2013-07-26 08:42:26 +0200 |
| commit | 21a1c51eef522e927709641f1b0459062c2c7ae9 (patch) | |
| tree | 2a33f5dd3184f0218101ce6503e42c6224e73b02 | |
| parent | d796de288e833da8d5a9c887a2270c5cab89331f (diff) | |
| download | libssh-21a1c51eef522e927709641f1b0459062c2c7ae9.tar.gz libssh-21a1c51eef522e927709641f1b0459062c2c7ae9.tar.xz libssh-21a1c51eef522e927709641f1b0459062c2c7ae9.zip | |
Check for NULL pointers in channels.c
| -rw-r--r-- | src/channels.c | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/src/channels.c b/src/channels.c index 214485c9..e51282fc 100644 --- a/src/channels.c +++ b/src/channels.c @@ -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 channel = NULL; + if(session == NULL) { + return NULL; + } + channel = malloc(sizeof(struct ssh_channel_struct)); if (channel == NULL) { ssh_set_error_oom(session); @@ -887,6 +891,10 @@ int channel_default_bufferize(ssh_channel channel, void *data, int len, * @see channel_request_exec() */ int ssh_channel_open_session(ssh_channel channel) { + if(channel == NULL) { + return SSH_ERROR; + } + #ifdef WITH_SSH1 if (channel->session->version == 1) { return channel_open_session1(channel); @@ -934,7 +942,6 @@ int ssh_channel_open_forward(ssh_channel channel, const char *remotehost, } session = channel->session; - enter_function(); if(remotehost == NULL || sourcehost == NULL) { @@ -1036,9 +1043,14 @@ void ssh_channel_free(ssh_channel channel) { * @see channel_free() */ int ssh_channel_send_eof(ssh_channel channel){ - ssh_session session = channel->session; + ssh_session session; int rc = SSH_ERROR; + if(channel == NULL) { + return rc; + } + + session = channel->session; enter_function(); if (buffer_add_u8(session->out_buffer, SSH2_MSG_CHANNEL_EOF) < 0) { @@ -1080,9 +1092,14 @@ error: * @see channel_eof() */ int ssh_channel_close(ssh_channel channel){ - ssh_session session = channel->session; + ssh_session session; int rc = 0; + if(channel == NULL) { + return SSH_ERROR; + } + + session = channel->session; enter_function(); if (channel->local_eof == 0) { @@ -1143,6 +1160,10 @@ int channel_write_common(ssh_channel channel, const void *data, return SSH_ERROR; } + if(channel == NULL || data == NULL) { + return -1; + } + session = channel->session; enter_function(); if(ssh_is_blocking(session)) 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 remoteport, const char *sourcehost, int localport) { - ssh_session session = channel->session; + ssh_session session; ssh_buffer payload = NULL; ssh_string str = NULL; int rc = SSH_ERROR; + if(channel == NULL) { + return rc; + } + + session = channel->session; + enter_function(); 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; int rc = SSH_ERROR; + if(channel == NULL) { + return SSH_ERROR; + } + #ifdef WITH_SSH1 if (channel->version == 1) { 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 * (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_string tmp = NULL; int rc = SSH_ERROR; |
