summaryrefslogtreecommitdiffstats
path: root/libssh/messages.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-01 19:44:19 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-01 19:44:19 +0000
commit54ce86e3b13750d5f49cc9c5e3cacaae74f86f61 (patch)
tree2da9069ab2fd126f90526877a4ac0550f54d0dbb /libssh/messages.c
parent904a5b2f7c94db6071022c5b26e9b1b4f187d367 (diff)
downloadlibssh-54ce86e3b13750d5f49cc9c5e3cacaae74f86f61.tar.gz
libssh-54ce86e3b13750d5f49cc9c5e3cacaae74f86f61.tar.xz
libssh-54ce86e3b13750d5f49cc9c5e3cacaae74f86f61.zip
Added memory error checks for message functions.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@321 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/messages.c')
-rw-r--r--libssh/messages.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/libssh/messages.c b/libssh/messages.c
index 3a8356a3..9b050a35 100644
--- a/libssh/messages.c
+++ b/libssh/messages.c
@@ -44,9 +44,13 @@
static SSH_MESSAGE *message_new(SSH_SESSION *session){
SSH_MESSAGE *msg=session->ssh_message;
- if(!msg){
- msg=malloc(sizeof(SSH_MESSAGE));
- session->ssh_message=msg;
+
+ if (msg == NULL) {
+ msg = malloc(sizeof(SSH_MESSAGE));
+ if (msg == NULL) {
+ return NULL;
+ }
+ session->ssh_message = msg;
}
memset(msg,0,sizeof (*msg));
msg->session=session;
@@ -87,7 +91,12 @@ static SSH_MESSAGE *handle_userauth_request(SSH_SESSION *session){
SSH_MESSAGE *msg;
char *service_c,*method_c;
enter_function();
- msg=message_new(session);
+
+ msg = message_new(session);
+ if (msg == NULL) {
+ return NULL;
+ }
+
msg->type=SSH_AUTH_REQUEST;
msg->auth_request.username=string_to_char(user);
free(user);
@@ -184,7 +193,10 @@ static SSH_MESSAGE *handle_channel_request_open(SSH_SESSION *session){
u32 sender, window, packet;
enter_function();
- msg=message_new(session);
+ msg = message_new(session);
+ if (msg == NULL) {
+ return NULL;
+ }
msg->type=SSH_CHANNEL_REQUEST_OPEN;
type=buffer_get_ssh_string(session->in_buffer);
type_c=string_to_char(type);
@@ -257,8 +269,13 @@ static SSH_MESSAGE *handle_channel_request(SSH_SESSION *session){
STRING *type;
char *type_c;
u8 want_reply;
- SSH_MESSAGE *msg=message_new(session);
+ SSH_MESSAGE *msg;
+
enter_function();
+ msg = message_new(session);
+ if (msg == NULL) {
+ return NULL;
+ }
buffer_get_u32(session->in_buffer,&channel);
channel=ntohl(channel);
type=buffer_get_ssh_string(session->in_buffer);