figiel / hosts

a libc wrapper providing per-user hosts file
Creative Commons Zero v1.0 Universal
65 stars 12 forks source link

crash on ssh #1

Closed jmdcal closed 9 years ago

jmdcal commented 9 years ago

the lib is causing segfaults in ssh tunnels

 ulimit  -c unlimited
ssh -L27017:dbhostname:27017 user@otherhose
Segmentation fault (core dumped)

gdb --core core.10262 `which ssh`
Core was generated by `ssh -L27017:db:27017 other'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  __strcmp_ssse3 () at ../sysdeps/x86_64/strcmp.S:983
983     movdqa  (%rdi), %xmm2
Missing separate debuginfos, use: debuginfo-install cyrus-sasl-lib-2.1.26-14.fc20.x86_64 keyutils-libs-1.5.9-1.fc20.x86_64 nspr-4.10.7-1.fc20.x86_64 nss-3.17.2-1.fc20.x86_64 nss-mdns-0.10-13.fc20.x86_64 nss-softokn-freebl-3.17.2-1.fc20.x86_64 nss-util-3.17.2-1.fc20.x86_64 openssl-libs-1.0.1e-40.fc20.x86_64 pcre-8.33-7.fc20.x86_64 xz-libs-5.1.2-12alpha.fc20.x86_64
(gdb) bt
#0  __strcmp_ssse3 () at ../sysdeps/x86_64/strcmp.S:983
#1  0x00007fb1247b9bb9 in find_alias_in_line () from /home/mdupont/.local/lib/libhostspriv.so
#2  0x00007fb1247b9cf0 in lookup_alias () from /home/mdupont/.local/lib/libhostspriv.so
#3  0x00007fb1247b9d9b in getaddrinfo () from /home/mdupont/.local/lib/libhostspriv.so
#4  0x00007fb124c07c3f in channel_setup_fwd_listener (type=type@entry=2, listen_addr=0x0, listen_port=27017, 
    allocated_listen_port=allocated_listen_port@entry=0x0, host_to_connect=<optimized out>, port_to_connect=27017, gateway_ports=0) at channels.c:2767
#5  0x00007fb124c0b453 in channel_setup_local_fwd_listener (listen_host=<optimized out>, listen_port=<optimized out>, host_to_connect=<optimized out>, 
    port_to_connect=<optimized out>, gateway_ports=<optimized out>) at channels.c:2933
#6  0x00007fb124beac73 in ssh_init_forwarding () at ssh.c:1145
#7  0x00007fb124be98bc in ssh_session2 () at ssh.c:1470
#8  main (ac=<optimized out>, av=<optimized out>) at ssh.c:993
neutronscott commented 9 years ago

I found that getaddrinfo can accept node==NULL. You can't strcmp NULL! I was able to fix like so:

static char *find_alias_in_line(char *hosts_line, const char *alias)
{
    char *strtok_saveptr, *ret, *hash, *token = NULL;

    if (alias == NULL)
        return NULL;
    ...
figiel commented 9 years ago

@neutronscott Could you fork & request a pull?