diff options
author | Denys Vlasenko | 2010-01-08 16:09:45 +0100 |
---|---|---|
committer | Denys Vlasenko | 2010-01-08 16:09:45 +0100 |
commit | 866710a05616be518d9d32261b52c9f81a025fe1 (patch) | |
tree | a0e37831c32f0fa9f373714b5f79a90d837efdbd /networking/nc_bloaty.c | |
parent | 8cd04d1cb658227d3c6eeb2a377314ca9cdf249d (diff) | |
download | busybox-866710a05616be518d9d32261b52c9f81a025fe1.zip busybox-866710a05616be518d9d32261b52c9f81a025fe1.tar.gz |
nc: fix "nc -nl -p LPORT RHOST" case (was expecting remote port 0). closes bug 837
function old new delta
dolisten 742 830 +88
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/nc_bloaty.c')
-rw-r--r-- | networking/nc_bloaty.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c index 9d7c23d..e14d512 100644 --- a/networking/nc_bloaty.c +++ b/networking/nc_bloaty.c @@ -340,16 +340,29 @@ create new one, and bind() it. TODO */ rr = accept(netfd, &remend.u.sa, &remend.len); if (rr < 0) bb_perror_msg_and_die("accept"); - if (themaddr && memcmp(&remend.u.sa, &themaddr->u.sa, remend.len) != 0) { - /* nc 1.10 bails out instead, and its error message - * is not suppressed by o_verbose */ - if (o_verbose) { - char *remaddr = xmalloc_sockaddr2dotted(&remend.u.sa); - bb_error_msg("connect from wrong ip/port %s ignored", remaddr); - free(remaddr); + if (themaddr) { + int sv_port, port, r; + + sv_port = get_nport(&remend.u.sa); /* save */ + port = get_nport(&themaddr->u.sa); + if (port == 0) { + /* "nc -nl -p LPORT RHOST" (w/o RPORT!): + * we should accept any remote port */ + set_nport(&remend, 0); /* blot out remote port# */ + } + r = memcmp(&remend.u.sa, &themaddr->u.sa, remend.len); + set_nport(&remend, sv_port); /* restore */ + if (r != 0) { + /* nc 1.10 bails out instead, and its error message + * is not suppressed by o_verbose */ + if (o_verbose) { + char *remaddr = xmalloc_sockaddr2dotted(&remend.u.sa); + bb_error_msg("connect from wrong ip/port %s ignored", remaddr); + free(remaddr); + } + close(rr); + goto again; } - close(rr); - goto again; } unarm(); } else |