aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-01 20:14:43 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-01 20:14:43 +0000
commitace6eed6c0c5e3493c58106cc0e698b92b7835f6 (patch)
treec74ffad8bc359c98aa6a55f4d836ffe7b1799cf3
parentcde3151634361e043340cbaef8e5fb04367a5b3d (diff)
downloadlibssh-ace6eed6c0c5e3493c58106cc0e698b92b7835f6.tar.gz
libssh-ace6eed6c0c5e3493c58106cc0e698b92b7835f6.tar.xz
libssh-ace6eed6c0c5e3493c58106cc0e698b92b7835f6.zip
Add memory error checking for sftpserver functions.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@327 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r--libssh/sftpserver.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/libssh/sftpserver.c b/libssh/sftpserver.c
index d60509a7..9176b55c 100644
--- a/libssh/sftpserver.c
+++ b/libssh/sftpserver.c
@@ -34,13 +34,21 @@
SFTP_CLIENT_MESSAGE *sftp_get_client_message(SFTP_SESSION *sftp){
- SFTP_PACKET *packet=sftp_packet_read(sftp);
- SFTP_CLIENT_MESSAGE *msg=malloc(sizeof (SFTP_CLIENT_MESSAGE));
+ SFTP_PACKET *packet;
+ SFTP_CLIENT_MESSAGE *msg;
BUFFER *payload;
STRING *tmp;
+
+ msg = malloc(sizeof (SFTP_CLIENT_MESSAGE));
+ if (msg == NULL) {
+ return NULL;
+ }
memset(msg,0,sizeof(SFTP_CLIENT_MESSAGE));
- if(!packet)
- return NULL;
+
+ packet = sftp_packet_read(sftp);
+ if (packet == NULL) {
+ return NULL;
+ }
payload=packet->payload;
msg->type=packet->type;
msg->sftp=sftp;
@@ -228,9 +236,13 @@ STRING *sftp_handle_alloc(SFTP_SESSION *sftp, void *info){
int i;
u32 val;
STRING *ret;
- if(!sftp->handles){
- sftp->handles=malloc(sizeof(void *) * SFTP_HANDLES);
- memset(sftp->handles,0,sizeof(void *)*SFTP_HANDLES);
+
+ if (sftp->handles == NULL) {
+ sftp->handles = malloc(sizeof(void *) * SFTP_HANDLES);
+ if (sftp->handles == NULL) {
+ return NULL;
+ }
+ memset(sftp->handles,0,sizeof(void *)*SFTP_HANDLES);
}
for(i=0; i<SFTP_HANDLES;++i)
if(!sftp->handles[i])