diff options
| author | Andreas Schneider <mail@cynapses.org> | 2009-04-14 08:55:33 +0000 |
|---|---|---|
| committer | Andreas Schneider <mail@cynapses.org> | 2009-04-14 08:55:33 +0000 |
| commit | 22b3122c6c297f7329100543afc7e712b3dc91d5 (patch) | |
| tree | 19baf76d5741cf36b5481d06320726b6d60ea422 /libssh | |
| parent | 640cf4cc93f92296fc6a8a4f64a7e2be0983f76e (diff) | |
| download | libssh-22b3122c6c297f7329100543afc7e712b3dc91d5.tar.gz libssh-22b3122c6c297f7329100543afc7e712b3dc91d5.tar.xz libssh-22b3122c6c297f7329100543afc7e712b3dc91d5.zip | |
Use consistent return values for packet_translate().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@456 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh')
| -rw-r--r-- | libssh/auth.c | 2 | ||||
| -rw-r--r-- | libssh/auth1.c | 4 | ||||
| -rw-r--r-- | libssh/channels.c | 3 | ||||
| -rw-r--r-- | libssh/packet.c | 44 | ||||
| -rw-r--r-- | libssh/session.c | 3 |
5 files changed, 32 insertions, 24 deletions
diff --git a/libssh/auth.c b/libssh/auth.c index 52fa9c2..d8ff54c 100644 --- a/libssh/auth.c +++ b/libssh/auth.c @@ -64,7 +64,7 @@ static int wait_auth_status(SSH_SESSION *session,int kbdint){ while(cont){ if(packet_read(session)) break; - if(packet_translate(session)) + if(packet_translate(session) != SSH_OK) break; switch(session->in_packet.type){ case SSH2_MSG_USERAUTH_FAILURE: diff --git a/libssh/auth1.c b/libssh/auth1.c index bea5a95..4f2b54c 100644 --- a/libssh/auth1.c +++ b/libssh/auth1.c @@ -32,11 +32,11 @@ #ifdef HAVE_SSH1 static int wait_auth1_status(SSH_SESSION *session) { /* wait for a packet */ - if (packet_read(session)) { + if (packet_read(session) != SSH_OK) { return SSH_AUTH_ERROR; } - if(packet_translate(session)) { + if(packet_translate(session) != SSH_OK) { return SSH_AUTH_ERROR; } diff --git a/libssh/channels.c b/libssh/channels.c index 5046517..c609a92 100644 --- a/libssh/channels.c +++ b/libssh/channels.c @@ -1223,7 +1223,8 @@ int channel_read(CHANNEL *channel, BUFFER *buffer, u32 bytes, int is_stderr) { break; /* return the resting bytes in buffer */ if(buffer_get_rest_len(stdbuf)>=maxread) // stop reading when buffer is full enough break; - if(packet_read(session)||packet_translate(session)){ + if ((packet_read(session)) != SSH_OK || + (packet_translate(session) != SSH_OK)) { leave_function(); return -1; } diff --git a/libssh/packet.c b/libssh/packet.c index 1895578..cda8383 100644 --- a/libssh/packet.c +++ b/libssh/packet.c @@ -373,24 +373,29 @@ int packet_read(SSH_SESSION *session) { return packet_read2(session); } -int packet_translate(SSH_SESSION *session){ - enter_function(); - memset(&session->in_packet,0,sizeof(PACKET)); - if(!session->in_buffer){ - leave_function(); - return -1; - } - ssh_log(session, SSH_LOG_RARE, "Final size %d", - buffer_get_rest_len(session->in_buffer)); - if(!buffer_get_u8(session->in_buffer,&session->in_packet.type)){ - ssh_set_error(session,SSH_FATAL,"Packet too short to read type"); - leave_function(); - return -1; - } - ssh_log(session, SSH_LOG_RARE, "Type %hhd", session->in_packet.type); - session->in_packet.valid=1; +int packet_translate(SSH_SESSION *session) { + enter_function(); + + memset(&session->in_packet, 0, sizeof(PACKET)); + if(session->in_buffer == NULL) { leave_function(); - return 0; + return SSH_ERROR; + } + + ssh_log(session, SSH_LOG_RARE, "Final size %d", + buffer_get_rest_len(session->in_buffer)); + + if(buffer_get_u8(session->in_buffer, &session->in_packet.type) == 0) { + ssh_set_error(session, SSH_FATAL, "Packet too short to read type"); + leave_function(); + return SSH_ERROR; + } + + ssh_log(session, SSH_LOG_RARE, "Type %hhd", session->in_packet.type); + session->in_packet.valid = 1; + + leave_function(); + return SSH_OK; } /* Write the the bufferized output. If the session is blocking, or enforce_blocking @@ -585,7 +590,8 @@ static int packet_wait1(SSH_SESSION *session,int type,int blocking){ enter_function(); ssh_log(session,SSH_LOG_PROTOCOL,"packet_wait1 waiting for %d",type); while(1){ - if(packet_read1(session) || packet_translate(session)){ + if ((packet_read1(session) != SSH_OK) || + (packet_translate(session) != SSH_OK)) { leave_function(); return -1; } @@ -637,7 +643,7 @@ static int packet_wait2(SSH_SESSION *session,int type,int blocking){ leave_function(); return ret; } - if(packet_translate(session)){ + if (packet_translate(session) != SSH_OK) { leave_function(); return SSH_ERROR; } diff --git a/libssh/session.c b/libssh/session.c index 9288542..1a69c36 100644 --- a/libssh/session.c +++ b/libssh/session.c @@ -215,7 +215,8 @@ int ssh_handle_packets(SSH_SESSION *session){ return r; // error or no data available } /* if an exception happened, it will be trapped by packet_read() */ - if(packet_read(session)||packet_translate(session)){ + if ((packet_read(session) != SSH_OK) || + (packet_translate(session) != SSH_OK)) { leave_function(); return -1; } |
