mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 02:38:09 +09:00
Add checks for memory errors in channel functions.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@314 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -48,6 +48,10 @@
|
|||||||
*/
|
*/
|
||||||
CHANNEL *channel_new(SSH_SESSION *session){
|
CHANNEL *channel_new(SSH_SESSION *session){
|
||||||
CHANNEL *channel=malloc(sizeof(CHANNEL));
|
CHANNEL *channel=malloc(sizeof(CHANNEL));
|
||||||
|
|
||||||
|
if (channel == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
memset(channel,0,sizeof(CHANNEL));
|
memset(channel,0,sizeof(CHANNEL));
|
||||||
channel->session=session;
|
channel->session=session;
|
||||||
channel->version=session->version;
|
channel->version=session->version;
|
||||||
@@ -1107,9 +1111,21 @@ int channel_select(CHANNEL **readchans, CHANNEL **writechans, CHANNEL **exceptch
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* prepare the outgoing temporary arrays */
|
/* prepare the outgoing temporary arrays */
|
||||||
rchans=malloc(sizeof(CHANNEL *) * (count_ptrs(readchans)+1));
|
rchans = malloc(sizeof(CHANNEL *) * (count_ptrs(readchans) + 1));
|
||||||
wchans=malloc(sizeof(CHANNEL *) * (count_ptrs(writechans)+1));
|
if (rchans == NULL) {
|
||||||
echans=malloc(sizeof(CHANNEL *) * (count_ptrs(exceptchans)+1));
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
wchans = malloc(sizeof(CHANNEL *) * (count_ptrs(writechans) + 1));
|
||||||
|
if (wchans == NULL) {
|
||||||
|
SAFE_FREE(rchans);
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
echans = malloc(sizeof(CHANNEL *) * (count_ptrs(exceptchans) + 1));
|
||||||
|
if (echans == NULL) {
|
||||||
|
SAFE_FREE(rchans);
|
||||||
|
SAFE_FREE(wchans);
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
/* first, try without doing network stuff */
|
/* first, try without doing network stuff */
|
||||||
/* then, select and redo the networkless stuff */
|
/* then, select and redo the networkless stuff */
|
||||||
|
|||||||
@@ -215,6 +215,10 @@ CHANNEL *ssh_message_channel_request_open_reply_accept(SSH_MESSAGE *msg){
|
|||||||
|
|
||||||
enter_function();
|
enter_function();
|
||||||
chan=channel_new(session);
|
chan=channel_new(session);
|
||||||
|
if (chan == NULL) {
|
||||||
|
leave_function();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
chan->local_channel=ssh_channel_new_id(session);
|
chan->local_channel=ssh_channel_new_id(session);
|
||||||
chan->local_maxpacket=35000;
|
chan->local_maxpacket=35000;
|
||||||
chan->local_window=32000;
|
chan->local_window=32000;
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ SFTP_SESSION *sftp_new(SSH_SESSION *session){
|
|||||||
memset(sftp,0,sizeof(SFTP_SESSION));
|
memset(sftp,0,sizeof(SFTP_SESSION));
|
||||||
sftp->session=session;
|
sftp->session=session;
|
||||||
sftp->channel=channel_new(session);
|
sftp->channel=channel_new(session);
|
||||||
|
if (sftp->channel == NULL) {
|
||||||
|
SAFE_FREE(sftp);
|
||||||
|
leave_function();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if(channel_open_session(sftp->channel)){
|
if(channel_open_session(sftp->channel)){
|
||||||
channel_free(sftp->channel);
|
channel_free(sftp->channel);
|
||||||
free(sftp);
|
free(sftp);
|
||||||
|
|||||||
Reference in New Issue
Block a user