It's not legal to free a coroutine's state structure before invoking
crFinish or crFinishV, since they will attempt to write to the
coroutine state variable contained in that structure. Introduced some
new all-in-one macros crFinishFree and crFinishFreeV, and used those
instead. Should fix today's report of a crash just after authentication.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9630 cda61777-01e9-0310-a592-d414129be87e
Don't close SSH-2 channels with outstanding channel requests on local error.

In sshfwd_unclean_close(), get ssh2_check_close() to handle sending
SSH_MSG_CHANNEL_CLOSE.  That way, it can hold off doing so until any
outstanding channel requests are processed.

Also add event log message for unclean channel closures.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9631 cda61777-01e9-0310-a592-d414129be87e
Slightly simplify crFinishFree{,V}.

They're only likely to be useful for freeing a coroutine state
structure, in which case there's no need to reset the line number
(since all such coroutines keep their line number in the state
structure) and the state structure pointer is always called "s".


git-svn-id: svn://svn.tartarus.org/sgt/putty@9632 cda61777-01e9-0310-a592-d414129be87e
Fix a memory leak in parse_ttymodes() (found by Memcheck/Valgrind).


git-svn-id: svn://svn.tartarus.org/sgt/putty@9633 cda61777-01e9-0310-a592-d414129be87e
Make bombout() less of a macro and more of a function.

This gives GCC slightly fewer opportunities to gratuitously inflate
its output.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9634 cda61777-01e9-0310-a592-d414129be87e
Change return type of do_ssh2_transport() to void.

Nothing pays attention to it any more, anyway.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9635 cda61777-01e9-0310-a592-d414129be87e
Clang, like LCC, objects to using '<' and '>' on function pointers.

I'm not entirely sure that using memcmp() is any more defined by the C
standard, but at least Clang doesn't complain about it.  While I'm
here, tree234 doesn't require that comparison functions return
precisely +1 or -1, so we can use the return value of memcmp()
directly.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9636 cda61777-01e9-0310-a592-d414129be87e
Partially revert r9636. It is true that we can directly return the
result of memcmp, but untrue that we can do so _unconditionally_: if
memcmp returns zero, we still need to fall through to the next
comparison.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9637 cda61777-01e9-0310-a592-d414129be87e
Fix a controlling-terminal bug reported by Anthony Heading: Cygwin
doesn't have TIOCSCTTY, so my attempt to set the ctty of the child
process isn't doing anything, and only works by chance when you run
bash because bash does the thing that _will_ set the ctty, namely
opening the terminal file again without O_NOCTTY. So now we do that
too.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9638 cda61777-01e9-0310-a592-d414129be87e
Avoid leaking file handles in load_openssh_key(), as reported by David
Wedderwille.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9642 cda61777-01e9-0310-a592-d414129be87e
In openssh_read(), we shouldn't ever return SSH2_WRONG_PASSPHRASE for
an unencrypted key. (The other import function, sshcom_read(), already
got this right.) Thanks to David Wedderwille for the report.

This is more than just an error-reporting mistake; it actually causes
Windows PuTTYgen to tight-loop on attempting to load a corrupt OpenSSH
key, because the 'wrong passphrase' return value causes the caller to
loop round and try again, but of course it knows the key is
unencrypted so it doesn't prompt for a different passphrase and just
tries again with no change...


git-svn-id: svn://svn.tartarus.org/sgt/putty@9643 cda61777-01e9-0310-a592-d414129be87e
Rename the various ssh2_maybe_setup_* functions to ssh2_setup_*, and
move the primary conditions out of them into their callers. Fixes a
crash in 'plink -N', since those functions would be called with a NULL
channel parameter and immediately dereference it to try to get c->ssh.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9644 cda61777-01e9-0310-a592-d414129be87e
Memory leak fixes reported by Balazs Domjan.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9645 cda61777-01e9-0310-a592-d414129be87e
do_ssh2_authconn() now installs the standard handlers for CHANNEL_SUCCESS 
and CHANNEL_FAILURE as soon as it's opened a channel, so there's no need
for it to set them again later.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9646 cda61777-01e9-0310-a592-d414129be87e
All of the initial CHANNEL_REQUESTs are conditional on (ssh->mainchan && 
!ssh->ncmode), so bundle them up in a big block conditional on this rather
than checking it five times.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9647 cda61777-01e9-0310-a592-d414129be87e
struct winadj is unused now.  G/c it.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9648 cda61777-01e9-0310-a592-d414129be87e
Factor out some common code for constructing SSH2_CHANNEL_OPEN.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9649 cda61777-01e9-0310-a592-d414129be87e
Hiroshi Oota points out that PuTTY's agent forwarding sockets can get
confused if they receive a request followed by immediate EOF, since we
currently send outgoing EOF as soon as we see the incoming one - and
then, when the response comes back from the real SSH agent, we send it
along anyway as channel data in spite of having sent EOF.

To fix this, I introduce a new field for each agent channel which
counts the number of calls to ssh_agentf_callback that are currently
expected, and we don't send EOF on an agent channel until we've both
received EOF and that value drops to zero.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9651 cda61777-01e9-0310-a592-d414129be87e
Most of the code for "nc" mode duplicated that for opening a session or
a fowarded port.  Arrange that this code is shared instead.  The main
visible change is a slight change of log messages.


git-svn-id: svn://svn.tartarus.org/sgt/putty@9655 cda61777-01e9-0310-a592-d414129be87e
In the cygwin Makefile, use "-o" on the windres command line to specify
the output file.  This appears to be supported by windres, and is
required by wrc (the Winelib resource compiler).


git-svn-id: svn://svn.tartarus.org/sgt/putty@9661 cda61777-01e9-0310-a592-d414129be87e