Commit Graph

1826 Commits

Author SHA1 Message Date
Daniel Stenberg
62cc59cd06 sftp_read: Value stored to 'next' is never read
Detected by clang-analyzer
2012-08-08 15:18:43 +02:00
Daniel Stenberg
1abf2057de publickey_init: errors are negative, fix check
Detected by clang-analyzer.
2012-08-08 15:15:30 +02:00
Maxime Larocque
6c27922ac1 session_free: wrong variable used for keeping state
If libssh2_session_free is called without the channel being freed
previously by libssh2_channel_free a memory leak could occur.

A mismatch of states variables in session_free() prevent the call to
libssh2_channel_free function. session->state member is used instead of
session->free_state.

It causes a leak of around 600 bytes on every connection on my systems
(Linux, x64 and PPC).

(Debugging done under contract for Accedian Networks)

Fixes #246
2012-07-25 01:08:03 +02:00
Guenter Knauf
112845df0b Small NetWare makefile tweak. 2012-06-29 17:20:56 +02:00
Guenter Knauf
499b22ca36 Some small Win32 makefile fixes. 2012-06-20 18:08:01 +02:00
Daniel Stenberg
6403519fcf libssh2_userauth_publickey_fromfile_ex.3: mention publickey == NULL 2012-06-19 22:08:45 +02:00
Daniel Stenberg
6f8dd9baff comp_method_zlib_decomp: handle Z_BUF_ERROR when inflating
When using libssh2 to perform an SFTP file transfer from the "JSCAPE MFT
Server" (http://www.jscape.com) the transfer failed. The default JSCAPE
configuration is to enforce zlib compression on SSH2 sessions so the
session was compressed. The relevant part of the debug trace contained:

 [libssh2] 1.052750 Transport: unhandled zlib error -5
 [libssh2] 1.052750 Failure Event: -29 - decompression failure

The trace comes from comp_method_zlib_decomp() in comp.c. The "unhandled
zlib error -5" is the status returned from the zlib function
inflate(). The -5 status corresponds to "Z_BUF_ERROR".

The inflate() function takes a pointer to a z_stream structure and
"inflates" (decompresses) as much as it can. The relevant fields of the
z_stream structure are:

  next_in - pointer to the input buffer containing compressed data
  avail_in - the number of bytes available at next_in
  next_out - pointer to the output buffer to be filled with uncompressed
             data
  avail_out - how much space available at next_out

To decompress data you set up a z_stream struct with the relevant fields
filled in and pass it to inflate(). On return the fields will have been
updated so next_in and avail_in show how much compressed data is yet to
be processed and next_out and avail_out show how much space is left in
the output buffer.

If the supplied output buffer is too small then on return there will be
compressed data yet to be processed (avail_in != 0) and inflate() will
return Z_OK. In this case the output buffer must be grown, avail_out
updated and inflate() called again.

If the supplied output buffer was big enough then on return the
compressed data will have been exhausted (avail_in == 0) and inflate()
will return Z_OK, so the data has all been uncompressed.

There is a corner case where inflate() makes no progress. That is, there
may be unprocessed compressed data and space available in the output
buffer and yet the function does nothing. In this case inflate() will
return Z_BUF_ERROR. From the zlib documentation and the source code it
is not clear under what circumstances this happens. It could be that it
needs to write multiple bytes (all in one go) from its internal state to
the output buffer before processing the next chunk of input but but
can't because there is not enough space (though my guesses as to the
cause are not really relevant). Recovery from Z_BUF_ERROR is pretty
simple - just grow the output buffer, update avail_out and call
inflate() again.

The comp_method_zlib_decomp() function does not handle the case when
inflate() returns Z_BUF_ERROR. It treats it as a non-recoverable error
and basically aborts the session.

Fixes #240
2012-06-14 16:11:48 +02:00
Guenter Knauf
a1c0d97ff9 MinGW makefile tweaks.
Use GNU tools when compiling on Linux.
Fixed dist and dev targets.
2012-06-12 01:03:14 +02:00
Guenter Knauf
5c065bf1ff NetWare makefile tweaks.
Changed to use Windows commandline tools instead of
GNU tools when compiling on Windows. Fixed dist and
dev targets. Enabled nlmconv error for unresolved
symbols.
2012-06-12 00:34:18 +02:00
Daniel Stenberg
5237177daf Revert "config.rpath: generated file, no need to keep in git"
This reverts commit 1ac7bd09cc.

This file still used by lib/*m4 functions so we need to keep the file
around.
2012-06-11 14:52:31 +02:00
Daniel Stenberg
bd627d38a1 BINDINGS: added PySsh2, a Python-ctypes binding 2012-06-09 00:14:17 +02:00
Guenter Knauf
c55b0b0425 Fixed MinGW debug build. 2012-06-08 08:03:24 +02:00
Daniel Stenberg
38efbe8243 BINDINGS: Added the Cocoa/Objective-C one
... and sorted the bindings after the languages, alphabetically

Reported by: Mike Abdullah
2012-06-05 15:43:50 +02:00
Daniel Stenberg
34ecc09a3c BINDINGS: document the bindings we know of 2012-06-05 11:40:51 +02:00
Guenter Knauf
d6cf1c7df0 Fixed LIBSSH2_INT64_T_FORMAT macro.
Usually a format macro should hold the whole format, otherwise
it should be named a prefix. Also fixed usage of this macro in
scp.c for a signed var where it was used as prefix for unsigned.
2012-06-04 22:54:25 +02:00
Guenter Knauf
a40c160cff Removed obsolete define from makefiles. 2012-06-04 17:01:27 +02:00
Guenter Knauf
29e256e817 Renamed NetWare makefiles. 2012-06-04 15:27:02 +02:00
Guenter Knauf
137342a41d Renamed NetWare makefiles. 2012-06-04 15:24:39 +02:00
Guenter Knauf
79a7ca3085 Synced MinGW makefiles with 56c64a6..39e438f.
Also synced MinGW test makefile with b092696..f8cb874.
2012-06-04 15:17:22 +02:00
Peter Stuge
50e37bdadc Revert "sftp: Don't send attrs.permissions on read-only SSH_FXP_OPEN"
This reverts commit 04e79e0c79.
2012-05-30 17:50:37 +02:00
Peter Stuge
04e79e0c79 sftp: Don't send attrs.permissions on read-only SSH_FXP_OPEN
This works around a protocol violation in the ProFTPD 1.3.4 mod_sftp
server, as reported by Will Cosgrove in:

http://libssh2.org/mail/libssh2-devel-archive-2012-05/0079.shtml

Based on a suggested fix by TJ Saunders in:

http://libssh2.org/mail/libssh2-devel-archive-2012-05/0104.shtml
2012-05-30 15:29:25 +02:00
Guenter Knauf
9a36065b52 Try to detect OpenSSL build type automatically.
Also fixed recently added libgdi32 linkage which is only
required when OpenSSL libs are linked statically.
2012-05-28 12:53:15 +02:00
Daniel Stenberg
1ac7bd09cc config.rpath: generated file, no need to keep in git 2012-05-25 09:07:18 +02:00
Guenter Knauf
9a7311ba57 Updated dependency libary versions. 2012-05-22 04:10:52 +02:00
Daniel Stenberg
e07b11b7df 1.4.3: towards the future 2012-05-18 23:44:07 +02:00
Daniel Stenberg
e885300b18 RELEASE-NOTES: synced with 92a9f95279 2012-05-18 23:30:04 +02:00
Alexander Lamaison
92a9f95279 win32/libssh2_config.h: Remove hardcoded #define LIBSSH2_HAVE_ZLIB.
Rationale: Everything else in this file states a fact about the win32
platform that is unconditional for that platform.  There is nothing
unconditional about the presence of zlib.  It is neither included with
Windows nor with the platform SDK.  Therefore, this is not an appropriate
place to assert its presence.  Especially as, once asserted, it cannot be
overridden using a compiler flag.

In contrast, if it is omitted, then it can easily be reasserted by adding
a compiler flag defining LIBSSH2_HAVE_ZLIB.
2012-05-15 17:32:06 +01:00
Daniel Stenberg
e91d4c9790 RELEASE-NOTES: synced with 69a3354467 2012-05-14 22:49:53 +02:00
Daniel Stenberg
69a3354467 _libssh2_packet_add: SSH_MSG_CHANNEL_REQUEST default to want_reply
RFC4254 says the default 'want_reply' is TRUE but the code defaulted to
FALSE. Now changed.

Fixes #233
2012-05-14 22:42:42 +02:00
Daniel Stenberg
3ede6e280e gettimeofday: no need for a replacement under cygwin
Fixes #224
2012-05-14 22:32:36 +02:00
Alexander Lamaison
b583311a93 Prevent sftp_packet_read accessing freed memory.
sftp_packet_add takes ownership of the packet passed to it and (now that we
handle zombies) might free the packet.  sftp_packet_read uses the packet type
byte as its return code but by this point sftp_packet_add might have freed
it.  This change fixes the problem by caching the packet type before calling
sftp_packet_add.

I don't understand why sftp_packet_read uses the packet type as its return
code.  A future change might get rid of this entirely.
2012-05-13 15:56:54 +01:00
Daniel Stenberg
27ac5aa40d sftp_packet_flush: flush zombies too
As this function is called when the SFTP session is closed, it needs to
also kill all zombies left in the SFTP session to avoid leaking memory
just in case some zombie would still be in there.
2012-05-12 22:42:40 +02:00
Daniel Stenberg
a123051200 sftp_packetlist_flush: zombies must not have responses already
When flushing the packetlist, we must only add the request as a zombie
if no response has already been received. Otherwise we could wrongly
make it a zombie even though the response was already received and then
we'd get a zombie stuck there "forever"...
2012-05-12 22:37:20 +02:00
Daniel Stenberg
62901253a4 sftp_read: on EOF remove packet before flush
Since the sftp_packetlist_flush() function will move all the existing
FXP_READ requests in this handle to the zombie list we must first remove
this just received packet as it is clearly not a zombie.
2012-05-10 23:11:07 +02:00
Daniel Stenberg
7c5ee0fa66 sftp_packet_require: sftp_packet_read() returning 0 is not an error
Exactly as the comment in the code said, checking the return code from
sftp_packet_read() with <= was wrong and it should be < 0. With the new
filtering on incoming packets that are "zombies" we can now see this
getting zero returned.
2012-05-10 23:09:37 +02:00
Daniel Stenberg
1e15075a8e sftp_packetlist_flush: only make it zombie if it was sent
The list of outgoing packets may also contain packets that never were
sent off and we better not make them zombies too.
2012-05-10 23:08:23 +02:00
Alexander Lamaison
ad63fc2df6 Mark outstanding read requests after EOF as zombies.
In order to be fast, sftp_read sends many read requests at once.  With a small
file, this can mean that when EOF is received back, many of these requests are
still outstanding.  Responses arriving after we close the file and abandon the
file handle are queued in the SFTP packet queue and never collected.  This
causes transfer speed to drop as a progressively longer queue must be searched
for every packet.

This change introduces a zombie request-ID list in the SFTP session that is
used to recognise these outstanding requests and prevent them being added to
the queue.
2012-05-10 19:35:25 +02:00
Rafael Kitover
d46185eaa5 Update win32/GNUmakefile to use OpenSSL 1.0.1a
libcrypto on win32 now depends on gdi32.dll, so move the OpenSSL LDLIBS
block to before the compiler definitions, so that libcrypto gets added
first, and then add -lgdi32 into the following common LDLIBS for gcc.
2012-04-23 20:04:41 +02:00
Guenter Knauf
9c4b380dd6 Changed 'Requires' to 'Requires.private'.
Only static builds need to link against the crypto libs.
2012-04-23 12:33:08 +02:00
Guenter Knauf
e887a8bd0f Fixed 'Requires:' names.
The 'Requires:' line lists the names of the .pc files.
2012-04-23 01:11:22 +02:00
Guenter Knauf
04692445d4 Added 'Requires:' line to libssh2.pc.
This is necessary so that other libs which lookup libssh2 info
via pkg-config can add the right crypto lib dependencies.
2012-04-23 00:35:03 +02:00
Guenter Knauf
a955f8428b Updated dependency lib versions. 2012-04-20 13:50:06 +02:00
Peter Stuge
ededdfa9c2 configure.ac: Add option to disable build of the example applications
Examples are built by default. Any of the following options on the
configure command line will skip building them:

  --disable-examples-build
  --enable-examples-build=no
  --enable-examples-build=false
2012-04-18 16:35:05 +02:00
Peter Stuge
11f9dce3d7 userauth.c: fread() from public key file to correctly detect any errors
If the filename parameter for file_read_publickey() was the name of a
directory instead of a file then libssh2 would spin trying to fgetc()
from the FILE * for the opened directory when trying to determine the
length of the encoded public key, since fgetc() can't report errors.

Use fread() instead to correctly detect this error condition along
with many others.

This fixes the problem reported in
http://www.libssh2.org/mail/libssh2-devel-archive-2012-04/0021.shtml

Reported-by: Oleksiy Zagorskyi <zalex_ua@i.ua>
2012-04-18 12:23:04 +02:00
Peter Stuge
6bbebcf36c Return LIBSSH2_ERROR_SOCKET_DISCONNECT on EOF when reading banner 2012-04-18 12:23:04 +02:00
Guenter Knauf
7a87bba02a Fixed copyright year. 2012-04-17 17:29:49 +02:00
Guenter Knauf
c8374cdc10 Updated dependency lib versions in static makefiles. 2012-04-12 22:01:45 +02:00
Daniel Stenberg
9b2bed22fc version: bump to 1.4.2
We're on the 1.4.2 track now (at least)
2012-04-06 15:28:18 +02:00
Daniel Stenberg
c8cc30c996 RELEASE-NOTES: updated for 1.4.1 release 2012-04-04 22:43:11 +02:00
Daniel Stenberg
acd9bd6104 always do "forced" window updates
When calling _libssh2_channel_receive_window_adjust() internally, we now
always use the 'force' option to prevent libssh2 to avoid sending the
update if the update isn't big enough.

It isn't fully analyzed but we have seen corner cases which made a
necessary window update not get send due to this and then the other side
doesn't send data our side then sits waiting for forever.
2012-04-03 22:36:19 +02:00