proxychains icon indicating copy to clipboard operation
proxychains copied to clipboard

Segmentation fault while resolving local hostname

Open tomsawyer-zz opened this issue 14 years ago • 4 comments

Hi, I'm getting segfault while connecting to any server by domain:

tom@hotmeal:~/workspace/proxychains_haad$ ./proxychains4 telnet google.com 80
[proxychains] config file found: /home/tom/workspace/proxychains_haad/proxychains.conf
[proxychains] preloading ./libproxychains4.so
DEBUG:init_lib_wrapper called from gcc_init
DEBUG:added localnet: netaddr=127.0.0.0, netmask=255.0.0.0
[proxychains] DLL init
DEBUG:loaded symbol 'connect' real addr 0x7fee8271ebd0  wrapped addr 0x7fee8342088a
DEBUG:loaded symbol 'gethostbyname' real addr 0x7fee82736bf0  wrapped addr 0x7fee83420c97
DEBUG:loaded symbol 'getaddrinfo' real addr 0x7fee826f89b0  wrapped addr 0x7fee83420dc9
DEBUG:loaded symbol 'freeaddrinfo' real addr 0x7fee826f9430  wrapped addr 0x7fee83420e7e
DEBUG:loaded symbol 'gethostbyaddr' real addr 0x7fee82736660  wrapped addr 0x7fee8342107f
DEBUG:loaded symbol 'getnameinfo' real addr 0x7fee8273ca90  wrapped addr 0x7fee83420efd
DEBUG:gethostbyname: tomhouse
Segmentation fault (core dumped)

While exploring the code I found that 'proxy_gethostbyname' returns a partially zeroed structure when trying to resolve local hostname, so it causes segfault in telnet (I think so).

tomsawyer-zz avatar Oct 09 '12 16:10 tomsawyer-zz

managed to fix it by inserting

    data->hostent_space.h_name = strdup(name); //it's a memory leak I think
    data->hostent_space.h_length = sizeof (in_addr_t);
    data->hostent_space.h_addrtype = AF_INET;

after

    if(data->resolved_addr == (in_addr_t) (-1))
        data->resolved_addr = (in_addr_t) (local_host.as_int);

in core.c

Besides, it's needed to add

    data->hostent_space.h_addrtype = AF_INET;

in 'have_ip' section or programs that directly uses gethostbyname() (such as perl) won't work. E.g.

proxychains4 GET cmyip.com

fails with

    LWP::Protocol::http::Socket: Bad hostname 'google.com' at /usr/share/perl5/LWP/Protocol/http.pm line 51.

tomsawyer-zz avatar Oct 09 '12 17:10 tomsawyer-zz

Can you submit this as pull-up request it's easier to merge and review that way.

haad avatar Oct 10 '12 11:10 haad

Also I would like to merge your changes, if you would like to see them in your parent repo.

haad avatar Oct 10 '12 11:10 haad

Stale issue message

github-actions[bot] avatar Jan 05 '25 03:01 github-actions[bot]