Bug 996 - Fatal error in xfree() when scp invokes ssh with a LocalForward config
Summary: Fatal error in xfree() when scp invokes ssh with a LocalForward config
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh (show other bugs)
Version: 4.0p1
Hardware: All All
: P2 normal
Assignee: OpenSSH Bugzilla mailing list
URL:
Keywords: openbsd, patch
Depends on:
Blocks: 994
  Show dependency treegraph
 
Reported: 2005-03-10 12:54 AEDT by Craig Leres
Modified: 2006-10-07 11:39 AEST (History)
0 users

See Also:


Attachments
minimal patch (605 bytes, patch)
2005-03-10 12:58 AEDT, Craig Leres
no flags Details | Diff
check forward listen_host for null (950 bytes, patch)
2005-03-10 16:53 AEDT, Darren Tucker
no flags Details | Diff
regress test for clearallforwardings bug (1.29 KB, patch)
2005-03-10 16:54 AEDT, Darren Tucker
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Craig Leres 2005-03-10 12:54:51 AEDT
The routine clear_forwardings() can call xfree() with a nil pointer if you have
a .ssh/config similar to this:

    Host mindrot.org
        LocalForward 12345 localhost:54321

This seems to happen with ssh when scp invokes it to connect to the remote host,
for example:

    % scp mindrot.org:.cshrc /dev/null
    xfree: NULL pointer given as argument

gdb shows this happens on this line in readconf.c:

    xfree(options->local_forwards[i].listen_host);

It's possible (perhaps likely) there are other similar problems in this routine.
Comment 1 Craig Leres 2005-03-10 12:58:52 AEDT
Created attachment 848 [details]
minimal patch
Comment 2 Darren Tucker 2005-03-10 14:26:57 AEDT
You are correct, it is a bug.  It can be provoked by using
ClearAllForwardings=yes (not just with scp).
Comment 3 Darren Tucker 2005-03-10 16:53:17 AEDT
Created attachment 849 [details]
check forward listen_host for null

I've been through the code and there appears to be one other instance of this
bug (immediately after the one you found) which is also fixed in this patch.

Basically, listen_host is new (it's to support the options to bind() port
forwards to specified addresses, and it's optional.  When it's not provided for
a particular forward, it's NULL.  When it's NULL and ClearAllForwardings is
set, ssh dies screaming.

As a workaround, prepending ":" to the forward spec should prevent it from
happening even without the patch.
Comment 4 Darren Tucker 2005-03-10 16:54:19 AEDT
Created attachment 850 [details]
regress test for clearallforwardings bug

Matching regress test.
Comment 5 Darren Tucker 2005-03-10 22:42:22 AEDT
This has now been fixed in OpenBSD, the fix will appear in -Portable next time
the changes are synced.  Thanks for the report.
Comment 6 Darren Tucker 2006-10-07 11:39:07 AEST
Change all RESOLVED bug to CLOSED with the exception of the ones fixed post-4.4.